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

◆ Bint4()

Sub Bint4 ( X() As  Double,
Y() As  Double,
Ndata As  Long,
Ibcl As  Long,
Ibcr As  Long,
Fbcl As  Double,
Fbcr As  Double,
Kntopt As  Long,
T() As  Double,
Bcoef() As  Double,
N As  Long,
K As  Long,
Info As  Long 
)

B-representation of the cubic spline interpolation

Purpose
This routine computes the B-representation (T(), Bcoef(), N, K) of a cubic spline (k = 4) which interpolates given data. The spline or any of its derivatives can be evaluated by calls to bvalu.

Parameters Ibcl, Ibcr, Fbcl, Fbcr allow the specification of the spline first or second derivative at both X(0) and X(Ndata-1). When this data is not specified by the problem, it is common practice to use a natural spline by setting second derivatives at X(0) and X(Ndata-1) to zero (Ibcl = Ibcr = 2, Fbcl = Fbcr = 0).

The spline is defined on T(3) <= X <= T(N) with (ordered) interior knots at X(i) values where N = Ndata+2. The knots T(0), T(1), T(2) lie to the left of T(3) = X(0) and the knots T(N+1), T(N+2), T(N+3) lie to the right of T(N) = X(Ndata-1) in increasing order. If no extrapolation outside [X(0), X(Ndata-1)] is anticipated, the knots T(0) = T(1) = T(2) = T(3) = X(0) and T(N) = T(N+1) = T(N+2) = T(N+3) = X(Ndata-1) can be specified by Kntopt = 1. Kntopt = 2 selects a knot placement for T(0), T(1), T(2) to make the first 7 knots symmetric about T(3) = X(0) and similarly for T(N+1), T(N+2), T(N+3) about T(N) = X(Ndata-1). Kntopt = 3 allows the user to make his own selection, in increasing order, for T(0), T(1), T(2) to the left of X(0) and T(N+1), T(N+2), T(N+3) to the right of X(Ndata-1). In any case, the interpolation on T(3) <= X <= T(N) by using function Bvalu is unique for given boundary conditions.
Parameters
[in]X()Array X(LX - 1) (LX >= Ndata)
X vector of abscissae, distinct and in increasing order.
[in]Y()Array Y(LY - 1) (LY >= Ndata)
Y vector of ordinates.
[in]NdataNumber of data points. (Ndata >= 2)
[in]IbclSelection parameter for left boundary condition.
= 1: Constrain the first derivative at X(0) to Fbcl.
= 2: Constrain the second derivative at X(0) to Fbcl.
[in]IbcrSelection parameter for right boundary condition.
= 1: Constrain the first derivative at X(Ndata - 1) to Fbcr.
= 2: Constrain the second derivative at X(Ndata - 1) to Fbcr.
[in]FbclLeft boundary values governed by Ibcl.
[in]FbcrRight boundary values governed by Ibcr.
[in]KntoptKnot selection parameter.
= 1: Sets knot multiplicity at T(3) and T(N) to 4.
= 2: Sets a symmetric placement of knots about T(3) and T(N).
= 3: The values of T(0)~T(2) and T(N+1)~T(N+3) are supplied by the user.
[in,out]T()Array T(LT - 1) (LT >= N + 4)
[in] When Kntopt = 3, the values of T(0)~T(2) and T(N+1)~T(N+3) are supplied.
[out] Knot values.
[out]Bcoef()Array Bcoef(LBcoef - 1) (LBcoef >= N)
B-spline coefficient array.
[out]NNumber of coefficients. (N = Ndata + 2)
[out]KOrder of spline. (K = 4)
[out]Info= 0: Successful exit.
= -1: The argument X() had an illegal value. (not distinct or not in increasing ordered)
= -2: The argument Y() is invalid.
= -3: The argument Ndata had an illegal value. (Ndata < 2)
= -4: The argument Ibcl had an illegal value. (Ibcl <> 1 and Ibcl <> 2)
= -5: The argument Ibcr had an illegal value. (Ibcr <> 1 and Ibcr <> 2)
= -8: The argument Kntopt had an illegal value. (Kntopt < 1 or Kntopt > 3)
= -9: The argument T() is invalid.
= -10: The argument Bcoef() is invalid.
= 1: The system of equations for computing coefficients is singular.
Reference
SLATEC
Example Program
Compute ln(0.115) by interpolating the following natural logarithm table with B-representation of the cubic spline (natuaral spline).
  x       ln(x)
------ ---------
 0.10   -2.3026
 0.11   -2.2073
 0.12   -2.1203
 0.13   -2.0402
------ ---------
Sub Ex_Bint4()
Const Ndata = 4
Dim X(Ndata - 1) As Double, Y(Ndata - 1) As Double, Xe As Double
Dim Ibcl As Long, Ibcr As Long, Fbcl As Double, Fbcr As Double, Kntopt As Long
Dim T(Ndata + 5) As Double, Bcoef(Ndata + 1) As Double, N As Long, K As Long
Dim Ideriv As Long, Inbv As Long, 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
'-- B-representation of cubic spline interpolation
Ibcl = 2: Fbcl = 0: Ibcr = 2: Fbcr = 0 '-- Natural spline
Kntopt = 1
Call Bint4(X(), Y(), Ndata, Ibcl, Ibcr, Fbcl, Fbcr, Kntopt, T(), Bcoef(), N, K, Info)
If Info <> 0 Then
Debug.Print "Error in Bint4: Info =", Info
Exit Sub
End If
'-- Compute interpolated values
Ideriv = 0: Inbv = 1
Xe = 0.115
Debug.Print "ln(" + CStr(Xe) + ") =", Bvalue(T(), Bcoef(), N, K, Ideriv, Xe, Inbv, Info)
Debug.Print "Info =", Info
End Sub
Sub Bint4(X() As Double, Y() As Double, Ndata As Long, Ibcl As Long, Ibcr As Long, Fbcl As Double, Fbcr As Double, Kntopt As Long, T() As Double, Bcoef() As Double, N As Long, K As Long, Info As Long)
B-representation of the cubic spline interpolation
Function Bvalue(T() As Double, A() As Double, N As Long, K As Long, Ideriv As Long, X As Double, Inbv As Long, Info As Long) As Double
Evaluation of function or derivative value for B-representation of B-spline
Example Results
ln(0.115) = -2.16266
Info = 0