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

◆ Chfev()

Sub Chfev ( X1 As  Double,
X2 As  Double,
F1 As  Double,
F2 As  Double,
D1 As  Double,
D2 As  Double,
Ne As  Long,
Xe() As  Double,
Fe() As  Double,
Nex() As  Long,
Info As  Long 
)

Cubic Hermite function values

Purpose
This routine evaluates a cubic polynomial given in Hermite form at an array of points, i.e. evaluates the cubic polynomial determined by function values f1, f2 and derivatives d1, d2 on interval [x1, x2] at the points Xe(j), j = 1 to Ne.

While designed for use by Pchfe, it may be useful directly as an evaluator for a piecewise cubic Hermite function in applications, such as graphing, where the interval is known in advance.
Parameters
[in]X1Endpoint of interval of definition of cubic. (X1 <> X2)
[in]X2Endpoint of interval of definition of cubic. (X1 <> X2)
[in]F1Value of function at X1.
[in]F2Value of function at X2.
[in]D1Value of derivative at X1.
[in]D2Value of derivative at X2.
[in]NeNumber of evaluation points. (Ne >= 1)
[in]Xe()Array Xe(LXe - 1) (LXe >= Ne)
Points at which the function is to be evaluated. If any of the Xe() are outside the interval [X1, X2], a warning error is returned in Nex().
[out]Fe()Array Fe(LFe - 1) (LFe >= Ne)
Values of the cubic function defined by X1, X2, F1, F2, D1, D2 at the points Xe().
[out]Nex()Array Nex(LNex - 1) (LNex >= 2)
Number of extrapolation points.
Nex(0) = number of evaluation points to left of interval.
Nex(1) = number of evaluation points to right of interval.
[out]Info= 0: Successful exit.
= -2: The argument X2 had an illegal value. (X2 = X1)
= -7: The argument Ne had an illegal value. (Ne < 1)
= -8: The argument Xe() is invalid.
= -9: The argument Fe() is invalid.
= -10: The argument Nex() is invalid.
Reference
SLATEC (PCHIP)
Example Program
Compute cubic spline interpolation of the following natural logarithm table. And compute ln(0.115) and ln(0.125) by evaluating the cubic polynomial on the interval [0.11, 0.12]. Nex(1) = 1 indicates that these is a evaluation point to right of interval (0.125 is outside the interval).
  x       ln(x)
------ ---------
 0.10   -2.3026
 0.11   -2.2073
 0.12   -2.1203
 0.13   -2.0402
------ ---------
Sub Ex_Chfev()
Const N = 4, Ne = 2
Dim X(N - 1) As Double, Y(N - 1) As Double, D(N - 1) As Double
Dim Ic(1) As Long, Vc(1) As Double
Dim Xe(Ne - 1) As Double, Ye(Ne - 1) As Double, Nex(1) As Long
Dim 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
'-- Compute interpolated values
Xe(0) = 0.115: Xe(1) = 0.125
Call Chfev(X(1), X(2), Y(1), Y(2), D(1), D(2), Ne, Xe(), Ye(), Nex(), Info)
Debug.Print "ln(" + CStr(Xe(0)) + ") =", Ye(0)
Debug.Print "ln(" + CStr(Xe(1)) + ") =", Ye(1)
Debug.Print "Info =", Info, "Nex(0) =", Nex(0), "Nex(1) =", Nex(1)
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 Chfev(X1 As Double, X2 As Double, F1 As Double, F2 As Double, D1 As Double, D2 As Double, Ne As Long, Xe() As Double, Fe() As Double, Nex() As Long, Info As Long)
Cubic Hermite function values
Example Results
ln(0.115) = -2.16285581089825
ln(0.125) = -2.07935612210228
Info = 0 Nex(0) = 0 Nex(1) = 1