|
|
◆ Bsplev()
| Sub Bsplev |
( |
T() As |
Double, |
|
|
Ad() As |
Double, |
|
|
N As |
Long, |
|
|
K As |
Long, |
|
|
Nderiv As |
Long, |
|
|
X As |
Double, |
|
|
Inev As |
Long, |
|
|
Svalue() As |
Double, |
|
|
Info As |
Long |
|
) |
| |
Evaluation of function and derivative values for B-representation of B-spline
- Purpose
- This routine computes the value of the B-spline and its derivatives at X from the B-representation (T(), A(), N, K) and returns them in Svalue(i) (i = 0 to Nderiv-1), where T(K-1) <= X <= T(N).
Ad(i) can be the B-spline coefficients A(i) (i = 0 to N-1) if Nderiv = 1. Otherwise Ad() must be computed beforehand by the following statement. Call Bspldr(T(), A(), N, K, Nderiv, Ad())
Sub Bspldr(T() As Double, A() As Double, N As Long, K As Long, Nderiv As Long, Ad() As Double, Info As Long) Construct a divided difference table from B-representation for derivative calculation by Bsplev
If X = T(i) (K-1 <= i <= N-1), right limiting values are obtained. To compute left derivatives or left limiting values at a knot T(i), replace N by i-1 and set X = T(i) (K <= i <= N).
- Parameters
-
| [in] | T() | Array T(LT - 1) (LT >= N + K)
Knot vector. |
| [in] | Ad() | Array Ad(LAd - 1) (LAd >= (2*N - Nderiv + 1)*Nderiv/2)
Divided difference table. |
| [in] | N | Number of B-spline coefficients. (N = sum of knot multiplicities - K) |
| [in] | K | Order of the B-spline. (K >= 1) |
| [in] | Nderiv | Number of the derivatives. (1 <= Nderiv <= K)
Nderiv = 1 returns the zero-th derivative = function value. |
| [in] | X | Argumrnt. (T(K-1) <= X <= T(N)) |
| [in,out] | Inev | An initialization parameter.
[in] Must be set to 1 when the first time Bsplev is called.
[out] Information for efficient processing after the initial call and Inev must not be changed by the user. Distinct splines require distinct Inev parameters. |
| [out] | Svalue() | Array Svalue(LSvalue - 1) (LSvalue >= Nderiv)
The spline value in Svalue(0) and the Nderiv-1 derivatives in the remaining components. |
| [out] | Info | = 0: Successful exit.
= -1: The argument T() is invalid.
= -2: The argument Ad() is invalid.
= -3: The argument N had an illegal value. (N < K)
= -4: The argument K had an illegal value. (K < 1)
= -5: The argument Nderiv had an illegal value. (Nderiv < 1 or Nderiv > K)
= -6: The argument X had an illegal value. (X < T(K-1) or X > T(N))
= -8: The argument Svalue() is invalid.
= 1: A left limiting value cannot be obtained at T(K-1). |
- Reference
- SLATEC
- Example Program
- Compute ln(0.115) and its derivative 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_Bsplev()
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 Nderiv As Long, Ad() As Double
Dim Inev As Long, Svalue() As Double, 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
'-- Prepare divided difference table for Bsplev
Nderiv = K
ReDim Ad((2 * N - Nderiv + 1) * Nderiv / 2 - 1)
Call Bspldr(T(), Bcoef(), N, K, Nderiv, Ad(), Info)
If Info <> 0 Then
Debug.Print "Error in Bspldr: Info =", Info
Exit Sub
End If
Xe = 0.115
Inev = 1
ReDim Svalue(Nderiv - 1)
Call Bsplev(T(), Ad(), N, K, Nderiv, Xe, Inev, Svalue(), Info)
If Info <> 0 Then
Debug.Print "Error in Bsplev: Info =", Info
Exit Sub
End If
Debug.Print "ln(" + CStr(Xe) + ") =", Svalue(0), "ln'(" + CStr(Xe) + ") =", Svalue(1)
Debug.Print "Info =", Info
End Sub
Sub Bsplev(T() As Double, Ad() As Double, N As Long, K As Long, Nderiv As Long, X As Double, Inev As Long, Svalue() As Double, Info As Long) Evaluation of function and derivative values for B-representation of B-spline
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
- Example Results
ln(0.115) = -2.16266 ln'(0.115) = 8.68833333333335
Info = 0
|