|
|
◆ Bsplvd()
| Sub Bsplvd |
( |
T() As |
Double, |
|
|
K As |
Long, |
|
|
Nderiv As |
Long, |
|
|
X As |
Double, |
|
|
Ileft As |
Long, |
|
|
Vnikx() As |
Double, |
|
|
Info As |
Long |
|
) |
| |
Compute the value and the derivatives of B-spline basis functions
- Purpose
- This routine computes the value and all derivatives of order less than Nderiv of all basis functions which do not (possibly) vanish at X.
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)
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
The output of Bsplvd is an array Vnikx(i,j) of dimension at least K x Nderiv whose columns contain the K nonzero basis functions and their Nderiv-1 right derivatives at X, i = 0 to K-1, j = 0 to Nderiv-1. These basis functions have indices Ileft-K+i, i = 1 to K, K <= Ileft <= N. The nonzero part of the i-th basis function lies in (T(i), T(i+K)), i = 0 to N-1). If X = T(Ileft) then Vnikx contains left limiting values (left derivatives) at T(Ileft). In particular, Ileft = N produces left limiting values at the right end point X = T(N). To obtain left limiting values at T(i), i = K to N, set X = next lower distinct knot, call Interv to get Ileft, set X = T(i), and then call 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] | K | Order of the B-spline. (K >= 1) |
| [in] | Nderiv | Number of derivatives + 1. (1 <= Nderiv <= K) |
| [in] | X | Argument of basis functions. (T(K - 1) <= X <= T(N)) |
| [in] | Ileft | Integer such that T(Ileft - 1) <= X <= T(Ileft). |
| [out] | Vnikx() | Array Vnikx(LVnikx1 - 1, LVnikx2 - 1) (LVnikx1 >= K, Lvnikx2 >= Nderiv)
Matrix containing the nonzero basis functions at X and their derivatives columnwise. |
| [out] | Info | = 0: Successful exit.
= -1: The argument T() is invalid.
= -2: The argument K had an illegal value. (K < 1)
= -3: The argument Nderiv had an illegal value. (Nderiv < 1 or Nderiv > K)
= -6: 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 Bsplvd and then compute the interpolated value of ln(0.115) and its derivative ln'(0.115).
x ln(x)
------ ---------
0.10 -2.3026
0.11 -2.2073
0.12 -2.1203
0.13 -2.0402
------ ---------
Sub Ex_Bsplvd()
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, Df As Double
Dim Nderiv As Long, 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 Bsplvd
Xe = 0.115
Ilo = 1
Call Interv(T(), N + K, Xe, Ilo, Ileft, Info)
If Ileft > N Then Ileft = N
Nderiv = 2
ReDim Vnikx(K - 1, Nderiv - 1)
Call Bsplvd(T(), K, Nderiv, Xe, Ileft, Vnikx(), Info)
If Info <> 0 Then
Debug.Print "Error in Bsplvd: Info =", Info
Exit Sub
End If
'-- Compute interpolated value
F = 0: Df = 0
For I = 0 To K - 1
F = F + Bcoef(Ileft - K + I) * Vnikx(I, 0)
Df = Df + Bcoef(Ileft - K + I) * Vnikx(I, 1)
Next
Debug.Print "ln(" + CStr(Xe) + ") =", F, "ln'(" + CStr(Xe) + ") =", Df
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 Bsplvd(T() As Double, K As Long, Nderiv As Long, X As Double, Ileft As Long, Vnikx() As Double, Info As Long) Compute the value and the derivatives of B-spline basis functions
- Example Results
ln(0.115) = -2.16266 ln'(0.115) = 8.68833333333335
Info = 0
|