XLPack 7.0
XLPack Numerical Library (Excel VBA) Reference Manual
Loading...
Searching...
No Matches

◆ Pchcm()

Sub Pchcm ( N As  Long,
X() As  Double,
F() As  Double,
D() As  Double,
Ismon() As  Long,
Info As  Long,
Optional Skip As  Boolean = False,
Optional Idxfd As  Long = 0,
Optional Incfd As  Long = 1 
)

Monotonicity check for piecewise cubic Hermite function

Purpose
This routine checks the piecewise cubic Hermite function defined by n, x[], f[], d[] for monotonicity.
Parameters
[in]NNumber of data points (N >= 2)
[in]X()Array X(LX - 1) (LX >= N)
Independent variable values. The elements of X() must be strictly increasing.
[in]F()Array F(LF - 1) (LF >= Incfd*(N - 1) + 1)
Function values. F(Idxfd + I*Incfd) is the value corresponding to X(I) (I = 0 to N - 1).
[in]D()Array D(LD - 1) (LD >= Incfd*(N - 1) + 1)
Derivative values. D(Idxfd + I*Incfd) is the value corresponding to X(I) (I = 0 to N - 1).
[out]Ismon()Array Ismon(LIsmon - 1) (LIsmon >= N)
An integer array indicating on which intervals the piecewise cubic Hermite function defined by N, X(), F(), D() is monotonic.
For data interval [X(I), X(I+1)] (I = 0 to N-2),
  Ismon(I) = -3 if function is probably decreasing
  Ismon(I) = -1 if function is strictly decreasing
  Ismon(I) = 0 if function is constant
  Ismon(I) = 1 if function is strictly increasing
  Ismon(I) = 2 if function is non-monotonic
  Ismon(I) = 3 if function is probably increasing
Ismon(N-1) indicates whether the entire function is monotonic on [X(0), X(N-1)].
[out]Info= 0: Successful exit.
= -1: The argument N had an illegal value. (N < 2)
= -2: The argument X() is invalid or had an illegal value. (X() is not strictly increasing)
= -3: The argument F() is invalid.
= -4: The argument D() is invalid.
= -5: The argument Ismon() is invalid.
= -9: The argument Incfd had an illegal value. (Incfd < 1)
[in]Skip(Optional)
Logical variable which should be set to True if the user wishes to skip checks for validity of preceding parameters, or to False otherwise. This will save time in case these checks have already been performed (say, in Pchim, Pchic, Pchsp or Pchse). (defaualt = False)
[in]Idxfd(Optional)
Index of the first data in F() and D(). (default = 0)
[in]Incfd(Optional)
Increment between successive values in F() and D(). (Incfd >= 1) (default = 1)
Reference
SLATEC (PCHIP)
Example Program
Check the piecewise cubic Hermite function interpolating the following natural logarithm table for monotonicity.
  x       ln(x)
------ ---------
 0.10   -2.3026
 0.11   -2.2073
 0.12   -2.1203
 0.13   -2.0402
------ ---------
Sub Ex_Pchcm()
Const N = 4
Dim X(N - 1) As Double, Y(N - 1) As Double, D(N - 1) As Double
Dim Ismon(N - 1) As Long, Info As Long
'-- Data
X(0) = 0.1: Y(0) = -2.3026
X(1) = 0.11: Y(1) = -2.2073
X(2) = 0.12: Y(2) = -2.1203
X(3) = 0.13: Y(3) = -2.0402
'-- Cubic Hermite interpolation
Call Pchim(N, X(), Y(), D(), Info)
If Info <> 0 Then
Debug.Print "Error in Pchim: Info =", Info
Exit Sub
End If
'-- Check monotonicity
Call Pchcm(N, X(), Y(), D(), Ismon(), Info)
Debug.Print Ismon(0), Ismon(1), Ismon(2), Ismon(3)
Debug.Print "Info =", Info
End Sub
Function Hermite(N As Long, X As Double, Optional Info As Long) As Double
Hermite polynomial Hn(x)
Sub Pchim(N As Long, X() As Double, F() As Double, D() As Double, Info As Long, Optional Idxfd As Long=0, Optional Incfd As Long=1)
Piecewise cubic Hermite interpolation (default boundary conditions)
Sub Pchcm(N As Long, X() As Double, F() As Double, D() As Double, Ismon() As Long, Info As Long, Optional Skip As Boolean=False, Optional Idxfd As Long=0, Optional Incfd As Long=1)
Monotonicity check for piecewise cubic Hermite function
Example Results
1 1 1 1
Info = 0