XLPack 6.1
Excel VBA Numerical Library (Basic module) Reference Manual
Loading...
Searching...
No Matches

◆ Pchse()

Sub Pchse ( 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 spline interpolation ("not a knot" condition)

Purpose
This routine computes the derivatives needed to determine the Hermite representation of the cubic spline interpolant to given data, with with the default boundary conditions ("not a knot" condition).

The resulting piecewise cubic spline function may be evaluated by Pchfe or Pchfd.
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)
Dependent variable values to be interpolated. F(Idxfd + I*Incfd) is the value corresponding to X(I) (I = 0 to N - 1).
[out]D()Array D(LD - 1) (LD >= Incfd*(N - 1) + 1)
Derivative values at the data points. These values will determine the cubic spline interpolant with the requested boundary conditions. The value corresponding to X(I) is stored in D(Idxfd + I*Incfd) (I = 0 to N - 1). No other entries in D() are changed.
[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.
= -7: The argument Incfd had an illegal value. (Incfd < 1)
[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(). This argument is provided primarily for 2-D applications. (Incfd >= 1) (default = 1)
Reference
SLATEC (PCHIP) (Driver for PCHSP)
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_Pchse()
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
'-- 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
'-- Spline interpolation
Call Pchse(N, X(), Y(), D(), Info)
If Info <> 0 Then
Debug.Print "Error in Pchse: 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
Example Results
ln(0.115) = -2.16285
ln(0.125) = -2.079475
Info = 0