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

◆ Bsplvn()

Sub Bsplvn ( T() As  Double,
Jhigh As  Long,
K As  Long,
Index As  Long,
X As  Double,
Ileft As  Long,
Vnikx() As  Double,
Info As  Long 
)

Compute the value of B-spline basis functions

Purpose
This routine computes the value of all (possibly) nonzero basis functions at X of order max(Jhigh, (j+1)*(Index-1)), where T(K-1) <= X <= T(N) and j = iwork is set to 1 inside the routine on the first call when Index = 1.

Ileft is input such that T(Ileft-1) <= X <= T(Ileft). The following statement produces the proper Ileft.
Call Interv(T(), N + 1, X, Ilo, Ileft, Info)\n
Sub Interv(Xt() As Double, Lxt As Long, X As Double, Ilo As Long, Ileft As Long, Info As Long)
Compute Ileft for the input to Bsplvd and Bsplvn
Bsplvn computes using the basic algorithm needed in Bsplvd. If only basis functions are desired, setting jhigh = K and index = 1 can be faster than calling Bsplvd. But extra coding is required for derivatives (Index = 2) and Bsplvd is set up for this purpose. Left limiting values are set up as described in Bsplvd.
Parameters
[in]T()Array T(LT - 1) (LT >= N + K)
Knot vector of length N + K, where N is number of B-spline basis functions (= sum of knot multiplicities - K).
[in]JhighOrder of B-spline to be computed. (1 <= Jhigh <= K)
[in]KHighest possible order. (K >= 1)
[in]Index= 1: The computation starts from scratch and the entire B-spline values of orders 1, 2, ..., Jhigh is generated order by order.
= 2: Only the B-spline values of order j+1, j+2, ..., Jhigh are generated. The previous entry for order j have to be saved.
[in]XArgument of basis functions. (T(K - 1) <= X <= T(N))
[in]IleftInteger such that T(Ileft - 1) <= X <= T(Ileft).
[out]Vnikx()Array Vnikx(LVnikx - 1) (LVnikx >= K)
Values of basis functions.
[out]Info= 0: Successful exit.
= -1: The argument T() is invalid.
= -2: The argument Jhigh had an illegal value. (Jhigh < 1 or Jhigh > K)
= -3: The argument K had an illegal value. (K < 1)
= -4: The argument Index had an illegal value. (Index <> 1 and Index <> 2)
= -7: The argument Vnikx() is invalid.
= 1: Ileft is not properly set. (X < T(Ileft-1) or X > T(Ileft))
Reference
SLATEC
Example Program
Compute the interpolation of the following natural logarithm table with B-representation of the cubic spline using Bint4. Using its coefficients, compute the value of B-spline basis function by Bsplvn and then compute the interpolated value of ln(0.115).
  x       ln(x)
------ ---------
 0.10   -2.3026
 0.11   -2.2073
 0.12   -2.1203
 0.13   -2.0402
------ ---------
Sub Ex_Bsplvn()
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 Vnikx() As Double, F As Double
Dim Ilo As Long, Ileft As Long, Info As Long, I 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 basis function values by Bsplvn
Xe = 0.115
Ilo = 1
Call Interv(T(), N + K, Xe, Ilo, Ileft, Info)
If Ileft > N Then Ileft = N
ReDim Vnikx(K - 1)
Call Bsplvn(T(), K, K, 1, Xe, Ileft, Vnikx(), Info)
If Info <> 0 Then
Debug.Print "Error in Bsplvn: Info =", Info
Exit Sub
End If
'-- Compute interpolated value
F = 0
For I = 0 To K - 1
F = F + Bcoef(Ileft - K + I) * Vnikx(I)
Next
Debug.Print "ln(" + CStr(Xe) + ") =", F
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
Sub Bsplvn(T() As Double, Jhigh As Long, K As Long, Index As Long, X As Double, Ileft As Long, Vnikx() As Double, Info As Long)
Compute the value of B-spline basis functions
Example Results
ln(0.115) = -2.16266
Info = 0