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

◆ Pchid()

Function Pchid ( N As  Long,
X() As  Double,
F() As  Double,
D() As  Double,
IA As  Long,
IB As  Long,
Info As  Long,
Optional Skip As  Boolean = False,
Optional Idxfd As  Long = 0,
Optional Incfd As  Long = 1 
)

Integral of piecewise cubic Hermite / cubic spline function (over an interval whose endpoints are data points)

Purpose
This routine evaluates the definite integral of a piecewise cubic Hermite function over an interval whose endpoints are data points. The interpolant is defined by N, X(), F() and D() computed by Pchim, Pchic, Pchsp or Pchse.
Returns
Double
Value of the requested integral.
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).
[in]IAIndex in X() for the lower limit of integration. (0 <= IA < IB <= N - 1)
[in]IBIndex in X() for the upper limit of integration. (0 <= IA < IB <= N - 1)
[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 IA had an illegal value. (IA < 0 or IA > N-1)
= -8: The argument IB had an illegal value. (IB < 0 or IB > N-1)
= -10: 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
Using the following table, compute S = integral of 1/(1 + x^2) dx [0, 4] (= atan(4)).
  x    1/(1 + x^2)
----- -------------
 -1        0.5
  0        1 
  1        0.5 
  2        0.2 
  3        0.1 
  4        0.05882
  5        0.03846
----- -------------
Sub Ex_Pchid()
Const N = 7, IA = 1, IB = 5
Dim X(N - 1) As Double, Y(N - 1) As Double, D(N - 1) As Double, S As Double
Dim Info As Long, I As Long
'-- Data
X(0) = -1: Y(0) = 0.5
X(1) = 0: Y(1) = 1
X(2) = 1: Y(2) = 0.5
X(3) = 2: Y(3) = 0.2
X(4) = 3: Y(4) = 0.1
X(5) = 4: Y(5) = 0.05882
X(6) = 5: Y(6) = 0.03846
'-- 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 integral 1/(1 + x^2) dx [0, 4] (= atan(4))
S = Pchid(N, X(), Y(), D(), IA, IB, Info)
Debug.Print "S =", S, "S(true) =", Atn(4)
Debug.Print "Info =", Info
End Sub
Function Pchid(N As Long, X() As Double, F() As Double, D() As Double, IA As Long, IB As Long, Info As Long, Optional Skip As Boolean=False, Optional Idxfd As Long=0, Optional Incfd As Long=1) As Double
Integral of piecewise cubic Hermite / cubic spline function (over an interval whose endpoints are dat...
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)
Example Results
S = 1.31070738095238 S(true) = 1.32581766366803
Info = 0