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

◆ Chfdv()

Sub Chfdv ( 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,
De() As  Double,
Nex() As  Long,
Info As  Long 
)

Cubic Hermite function and derivative values

Purpose
This routine evaluates a cubic polynomial given in Hermite form and its first derivative 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], together with its first derivative, at the points Xe(j), j = 1 to Ne.

While designed for use by Pchfd, 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.

If only function values are required, use Chfev instead.
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]De()Array De(LDe - 1) (LDe >= Ne)
Values of the first derivative 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 De() is invalid.
= -11: 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) and their derivatives 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_Chfdv()
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, Yep(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 Chfdv(X(1), X(2), Y(1), Y(2), D(1), D(2), Ne, Xe(), Ye(), Yep(), Nex(), Info)
Debug.Print "ln(" + CStr(Xe(0)) + ") =", Ye(0), "ln'(" + CStr(Xe(0)) + ") =", Yep(0)
Debug.Print "ln(" + CStr(Xe(1)) + ") =", Ye(1), "ln'(" + CStr(Xe(1)) + ") =", Yep(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 Chfdv(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, De() As Double, Nex() As Long, Info As Long)
Cubic Hermite function and derivative values
Example Results
ln(0.115) = -2.16285581089825 ln'(0.115) = 8.6907851599008
ln(0.125) = -2.07935612210228 ln'(0.125) = 8.04601195968914
Info = 0 Nex(0) = 0 Nex(1) = 1