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

◆ Pchim()

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)

Purpose
This routine sets derivatives needed to determine a monotone piecewise cubic Hermite interpolant. Default boundary conditions are provided which are compatible with monotonicity. Use Pchic if user control of boundary conditions is desired.

The resulting piecewise cubic Hermite function may be evaluated by Pchfe or Pchfd.
Parameters
[in]NNumber of data points. (N >= 2)
If N = 2, simply does linear interpolation.
[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)
Dependent variable values to be interpolated.
[out]D()Array D(LD - 1) (LD >= Incfd*(N - 1) + 1)
Derivative values at the data points.
[out]Info= 0: Successful exit.
= -1: The argument N had an illegal value. (N < 2)
= -2: The argument X() had an illegal value. (X() is not strictly increasing)
= -3: The argument F() is invalid.
= -4: The argument D() is invalid.
= -7: The argument Incfd had an illegal value. (Incfd < 1)
= i > 0: i switches in the direction of monotonicity were detected.
[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
Compute ln(0.115) and ln(0.125) by interpolating the following natural logarithm table with cubic spline.
  x       ln(x)
------ ---------
 0.10   -2.3026
 0.11   -2.2073
 0.12   -2.1203
 0.13   -2.0402
------ ---------
Sub Ex_Pchim()
Const N = 4, Ne = 2
Dim X(N - 1) As Double, Y(N - 1) As Double, D(N - 1) As Double
Dim Xe(Ne - 1) As Double, Ye(Ne - 1) As Double
Dim Info As Long, I 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
'-- Compute interpolated values
Xe(0) = 0.115: Xe(1) = 0.125
Call Pchfe(N, X(), Y(), D(), Ne, Xe(), Ye(), Info)
Debug.Print "ln(" + CStr(Xe(0)) + ") =", Ye(0)
Debug.Print "ln(" + CStr(Xe(1)) + ") =", Ye(1)
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 Pchfe(N As Long, X() As Double, F() As Double, D() As Double, Ne As Long, Xe() As Double, Fe() As Double, Info As Long, Optional Skip As Boolean=False, Optional Idxfd As Long=0, Optional Incfd As Long=1)
Evaluation of function values for piecewise cubic Hermite (and cubic spline) interpolation
Example Results
ln(0.115) = -2.16285581089825
ln(0.125) = -2.07940530745063
Info = 0