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

◆ Pchia()

Function Pchia ( N As  Long,
X() As  Double,
F() As  Double,
D() As  Double,
A As  Double,
B As  Double,
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

Purpose
This routine evaluates the definite integral of a piecewise cubic Hermite function over an arbitrary interval. 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]ALower limit of integration.
[in]BUpper limit of integration.
Note - There is no requirement that [A, B] be contained in [X(0), X(N - 1)]. However, the resulting integral value will be highly suspect, if not.
[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. (not distinct or not in increasing order)
= -3: The argument F() is invalid.
= -4: The argument D() is invalid.
= -10: The argument Incfd had an illegal value. (Incfd < 1)
= 1: A is outside the interval [X(0), X(N-1)].
= 2: B is outside the interval [X(0), X(N-1)].
= 3: Both of the above are true.
[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_Pchia()
Const N As Long = 7, A As Double = 0, B As Double = 4
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 = Pchia(N, X(), Y(), D(), A, B, Info)
Debug.Print "S =", S, "S(true) =", Atn(4)
Debug.Print "Info =", Info
End Sub
Function Pchia(N As Long, X() As Double, F() As Double, D() As Double, A As Double, B As Double, 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
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