|
|
◆ Pchbs()
| Sub Pchbs |
( |
N As |
Long, |
|
|
X() As |
Double, |
|
|
F() As |
Double, |
|
|
D() As |
Double, |
|
|
Knotyp As |
Long, |
|
|
Nknots As |
Long, |
|
|
T() As |
Double, |
|
|
Bcoef() As |
Double, |
|
|
Ndim As |
Long, |
|
|
Kord As |
Long, |
|
|
Info As |
Long, |
|
|
Optional Idxfd As |
Long = 0, |
|
|
Optional Incfd As |
Long = 1 |
|
) |
| |
Piecewise cubic Hermite to B-spline conversion
- Purpose
- This routine computes the B-spline representation of the piecewise cubic Hermite function determined by N, X(), F() and D(). The output is the B-representation for the function: Nknots, T(), Bcoef(), Ndim and Kord.
Since it is assumed that the input piecewise cubic Hermite function has been computed by one of the other routines in the package, input arguments N, X(), Incfd are not completely checked for validity.
Restrictions and assumptions are:
- N >= 2 (error return if not)
- X(i) < X(i+1), i = 0 to n-1 (not checked)
- Incfd > 0 (error return if not)
- Knotyp <= 2 (error return if not)
- (*) Nknots = Ndim + 4 = 2*N + 4 (error return if not)
- (*) T(2*k + 1) = T(2*k) = X(k), k = 0 to n-1 (not checked)
(*): indicates this applies only if Knotyp < 0.
- Parameters
-
| [in] | N | Number 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] | Knotyp | Flag to control the knot sequence.
The knot sequence T() is normally computed from X by putting a double knot at each X and setting the end knot pairs according to the value of Knotyp.
= 0: Quadruple knots at X(0) and X(N-1)
= 1: Replicate lengths of extreme subintervals:
T(0) = T(1) = X(0) - (X(1) - X(0))
T(M + 3) = T(M + 2) = X(N - 1) + (X(N - 1) - X(N - 2))
= 2: Periodic placement of boundary knots:
T(0) = T(1) = X(0) - (X(N - 1) - X(N - 2))
T(M + 3) = T(M + 2) = X(N - 1) + (X(1) - X(0))
Here M = Ndim = 2 * N.
If the input value of Knotyp is negative, however, it is assumed that Nknots and T() were set in a previous call. This option is provided for improved efficiency when used in a parametric setting. |
| [in,out] | Nknots | Number of knots.
[in] When Knotyp < 0: Nknots is an input variable, and an error return will be taken if it is not equal to Ndim + 4.
[out] When Knotyp >= 0: Nknots will be set to Ndim + 4. |
| [in,out] | T() | Array T(LT - 1) (LT >= 2 * N + 4)
Knots for the B-representation.
[in] When Knotyp < 0: It is assumed that T() was set by a previous call to Pchbs (This routine does not verify that T() forms a legitimate knot sequence).
[out] When Knotyp >= 0: T() will be returned by Pchbs with the interior double knots equal to the X-values and the boundary knots set as indicated above. |
| [out] | Bcoef() | Array Bcoef(LBcoef - 1) (LBcoef >= 2 * N)
B-spline coefficients. |
| [out] | Ndim | Dimension of the B-spline space (to be set to 2 * N). |
| [out] | Kord | Order of the B-spline (to be set to 4). |
| [out] | Info | = 0: Successful exit.
= -1: The argument N had an illegal value. (N < 2)
= -2: The argument X() is invalid.
= -3: The argument F() is invalid.
= -4: The argument D() is invalid.
= -5: The argument Knotyp had an illegal value. (Knotyp > 2)
= -6: The argument Nknots had an illegal value. (Nknots <> 2*N+4 when Knotyp < 0)
= -7: The argument T() is invalid.
= -8: The argument Bcoef() is invalid.
= -13: The argument Incfd had an illegal value. (Incfd < 1) |
| [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
- Compute the B-spline representation of the piecewise cubic Hermite interpolation of the following natural logarithm table.
x ln(x)
------ ---------
0.10 -2.3026
0.11 -2.2073
0.12 -2.1203
0.13 -2.0402
------ ---------
Sub Ex_Pchbs()
Const N = 4, Ne = 2
Dim X(N - 1) As Double, Y(N - 1) As Double, D(N - 1) As Double
Dim Ic(1) As Long, Vc(1) As Double
Dim Knotyp As Long, Nknots As Long, T(2 * N + 3) As Double, Bcoef(2 * N - 1) As Double
Dim Ndim As Long, Kord As Long
Dim 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
Ic(0) = 1: Ic(1) = 1
Vc(0) = 1 / X(0): Vc(1) = 1 / X(3)
Call Pchic(Ic(), Vc(), 0, N, X(), Y(), D(), Info)
If Info <> 0 Then
Debug.Print "Error in Pchic: Info =", Info
Exit Sub
End If
'-- Convert to B-spline
Knotyp = 0
Call Pchbs(N, X(), Y(), D(), Knotyp, Nknots, T(), Bcoef(), Ndim, Kord, Info)
Debug.Print "Info =", Info
End Sub
Function Hermite(N As Long, X As Double, Optional Info As Long) As Double Hermite polynomial Hn(x)
Sub Pchbs(N As Long, X() As Double, F() As Double, D() As Double, Knotyp As Long, Nknots As Long, T() As Double, Bcoef() As Double, Ndim As Long, Kord As Long, Info As Long, Optional Idxfd As Long=0, Optional Incfd As Long=1) Piecewise cubic Hermite to B-spline conversion
Sub Pchic(Ic() As Long, Vc() As Double, Switch As Double, 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 Hermite interpolation
|