NAG Library Routine Document
E02BFF
1 Purpose
E02BFF evaluates a cubic spline and up to its first three derivatives from its B-spline representation at a vector of points. E02BFF can be used to compute the values and derivatives of cubic spline fits and interpolants produced by
E02BAF and
E02BEF.
2 Specification
SUBROUTINE E02BFF ( |
START, NCAP7, LAMDA, C, DERIV, XORD, X, IXLOC, NX, S, LDS, IWRK, LIWRK, IFAIL) |
INTEGER |
START, NCAP7, DERIV, XORD, IXLOC(NX), NX, LDS, IWRK(LIWRK), LIWRK, IFAIL |
REAL (KIND=nag_wp) |
LAMDA(NCAP7), C(NCAP7), X(NX), S(LDS,*) |
|
3 Description
E02BFF evaluates the cubic spline
and optionally derivatives up to order
for a vector of points
, for
. It is assumed that
is represented in terms of its B-spline coefficients
, for
, and (augmented) ordered knot set
, for
,
(see
E02BAF and
E02BEF),
i.e.,
Here , is the number of intervals of the spline and denotes the normalized B-spline of degree (order ) defined upon the knots .
Only abscissae satisfying,
will be evaluated. At a simple knot
(i.e., one satisfying
), the third derivative of the spline is, in general, discontinuous. At a multiple knot (i.e., two or more knots with the same value), lower derivatives, and even the spline itself, may be discontinuous. Specifically, at a point
where (exactly)
knots coincide (such a point is termed a knot of multiplicity
), the values of the derivatives of order
, for
, are, in general, discontinuous. (Here
;
is not meaningful.) The maximum order of the derivatives to be evaluated must be specified (
), as must their left- (
) or right- (
) handedness when evaluated at the knots.
Each abscissa (point at which the spline is to be evaluated)
contained in X has an associated enclosing interval number,
either supplied or returned in
IXLOC (see
START). A simple call to E02BFF would set
START to zero and the contents of
IXLOC need never be set nor referenced, and the following description on modes of operation can be ignored. However, where efficiency is an important consideration, the following description will help to choose the appropriate mode of operation.
The interval numbers are used to determine which B-splines must be evaluated for a given abscissa, and are defined as
The algorithm has two modes of vectorization, termed here sorted and unsorted, which are selectable by the parameter
START. The sorted mode has two phases, a sorting phase and an evaluation phase. This mode is recommended if there are many abscissae to evaluate relative to the number of intervals of the spline, or the abscissae are distributed relatively densely over a subsection of the spline. In the first phase,
is determined for each
and a permutation is calculated to sort the
by interval number. The first phase may be either partially or completely by-passed using the parameter
START if the enclosing segments and/or the subsequent ordering are already known
a priori, for example if multiple spline coefficients
C are to be evaluated over the same set of knots
LAMDA.
In the second phase of the sorted mode, spline approximations are evaluated by segment, so that non-abscissae dependent calculations over a segment may be reused in the evaluation for all abscissa belonging to a specific segment. For example, all third derivatives of all abscissae in the same segment will be identical.
In the unsorted mode of vectorization, no
a priori segment sorting is performed, and the evaluation at an abscissa is independent of evaluations at other abscissae; also non-abscissae dependent calculations over a segment will be repeated for each abscissa in a segment. This may be quicker if the number of absicssae is small in comparison to the number of knots in the spline, and they are distributed sparsely throughout the domain of the spline. This is effectively a direct vectorization of
E02BBF and
E02BCF, although if the enclosing interval numbers
are known, these may again be provided.
If no derivatives are required, the spline evaluation is calculated by taking convex combinations due to
de Boor (1972). Otherwise, the calculation of
and its derivatives is based upon,
(i) |
evaluating the nonzero B-splines of orders , , and by recurrence (see Cox (1972) and Cox (1978)), |
(ii) |
computing all derivatives of the B-splines of order by applying a second recurrence to these computed B-spline values (see de Boor (1972)), |
(iii) |
multiplying the fourth-order B-spline values and their derivative by the appropriate B-spline coefficients, and summing, to yield the values of and its derivatives. |
The method of convex combinations is significantly faster than the recurrence based method. If higher derivatives of order or are not required, as much computation as possible is avoided.
4 References
Cox M G (1972) The numerical evaluation of B-splines J. Inst. Math. Appl. 10 134–149
Cox M G (1978) The numerical evaluation of a spline from its B-spline representation J. Inst. Math. Appl. 21 135–143
de Boor C (1972) On calculating with B-splines J. Approx. Theory 6 50–62
5 Parameters
- 1: START – INTEGERInput
On entry: indicates the completion state of the first phase of the algorithm.
- The enclosing interval numbers for the abscissae contained in X have not been determined, and you wish to use the sorted mode of vectorization.
- The enclosing interval numbers have been determined and are provided in IXLOC, however the required permutation and interval related information has not been determined and you wish to use the sorted mode of vectorization.
- You wish to use the sorted mode of vectorization, and the entire first phase has been completed, with the enclosing interval numbers supplied in IXLOC, and the required permutation and interval related information provided in IWRK (from a previous call to E02BFF).
- The enclosing interval numbers for the abscissae contained in X have not been determined, and you wish to use the unsorted mode of vectorization.
- The enclosing interval numbers for the abscissae contained in X have been supplied in IXLOC, and you wish to use the unsorted mode of vectorization.
Constraint:
, , , or .
Additional: or should be used unless you are sure that the knot set is unchanged between calls.
- 2: NCAP7 – INTEGERInput
On entry:
, where
is the number of intervals of the spline (which is one greater than the number of interior knots, i.e., the knots strictly within the range
to
over which the spline is defined). Note that if
E02BEF was used to generate the knots and spline coefficients then
NCAP7 should contain the same value as returned in
N by
E02BEF.
Constraint:
.
- 3: LAMDA(NCAP7) – REAL (KIND=nag_wp) arrayInput
On entry: must be set to the value of the th member of the complete set of knots, , for .
Constraint:
the must be in nondecreasing order with .
- 4: C(NCAP7) – REAL (KIND=nag_wp) arrayInput
On entry: the coefficient
of the B-spline , for . The remaining elements of the array are not referenced.
- 5: DERIV – INTEGERInput
On entry: the order of derivatives required.
If
left derivatives are calculated, otherwise right derivatives are calculated. For abscissae satisfying
or
only right or left derivatives will be computed respectively. For abscissae which do not coincide exactly with a knot, the sign of
DERIV is immaterial.
- No derivatives required.
- Only and its first derivative are required.
- Only and its first and second derivatives are required.
- and its first, second and third derivatives are required.
Note: if is greater than only the derivatives up to and including will be returned.
- 6: XORD – INTEGERInput
On entry: indicates whether
X is supplied in a sufficiently ordered manner. If
X is sufficiently ordered E02BFF will complete faster.
- The abscissae in X are ordered at least by interval, in that any two abscissae contained in the same interval are only separated by abscissae in the same interval. For example, , for .
- The abscissae in X are not sufficiently ordered.
- 7: X(NX) – REAL (KIND=nag_wp) arrayInput
On entry: the abscissae
, for . Evaluations will only be performed for those satisfying .
Constraint:
at least one abscissa must fall between and .
- 8: IXLOC(NX) – INTEGER arrayInput/Output
On entry: if
,
or
, if you wish
to be evaluated,
must be the enclosing interval number
of the abscissae
(see
(1)). If you do not wish
to be evaluated, you may set the interval number to be either less than
or greater than
.
Otherwise,
IXLOC need not be set.
On exit: if
,
or
,
IXLOC is unchanged on exit.
Otherwise,
, for
, contains the enclosing interval number
, supplied in
X, for
. Evaluations will only take place for abscissae
with
.
Constraint:
if
,
or
, at least one element of
IXLOC must be between
and
.
- 9: NX – INTEGERInput
On entry:
, the total number of abscissae contained in
X, including any that will not be evaluated.
Constraint:
.
- 10: S(LDS,) – REAL (KIND=nag_wp) arrayOutput
-
Note: the second dimension of the array
S
must be at least
.
On exit: if
is valid,
will contain the (
)th derivative of
, for
and
. In particular,
will contain the approximation of
for all legal values in
X.
- 11: LDS – INTEGERInput
On entry: the first dimension of the array
S as declared in the (sub)program from which E02BFF is called.
Constraint:
, regardless of the acceptability of the elements of
X.
- 12: IWRK(LIWRK) – INTEGER arrayInput/Output
On entry: if
,
IWRK must be unchanged from a previous call to E02BFF with
or
.
Otherwise,
IWRK need not be set.
On exit: if
,
IWRK is unchanged on exit.
Otherwise,
IWRK contains the required permutation of elements of
X, if any, and information related to the division of the abscissae
between the intervals derived from
LAMDA.
- 13: LIWRK – INTEGERInput
On entry: the dimension of the array
IWRK as declared in the (sub)program from which E02BFF is called.
Constraint:
.
- 14: IFAIL – INTEGERInput/Output
-
On entry:
IFAIL must be set to
,
. If you are unfamiliar with this parameter you should refer to
Section 3.3 in the Essential Introduction for details.
For environments where it might be inappropriate to halt program execution when an error is detected, the value
is recommended. If the output of error messages is undesirable, then the value
is recommended. Otherwise, because for this routine the values of the output parameters may be useful even if
on exit, the recommended value is
.
When the value is used it is essential to test the value of IFAIL on exit.
On exit:
unless the routine detects an error or a warning has been flagged (see
Section 6).
6 Error Indicators and Warnings
If on entry
or
, explanatory error messages are output on the current error message unit (as defined by
X04AAF).
Note: E02BFF may return useful information for one or more of the following detected errors or warnings.
Errors or warnings detected by the routine:
-
On entry, at least one element of
X has an enclosing interval number in
IXLOC outside the set allowed by the provided spline.
entries of
X were indexed below the lower bound
.
entries of
X were indexed above the upper bound
.
-
On entry, all elements of
X had enclosing interval numbers in
IXLOC outside the domain allowed by the provided spline.
entries of
X were indexed below the lower bound
.
entries of
X were indexed above the upper bound
.
-
On entry, .
Constraint: , , , or .
-
On entry,
and
NX is not consistent with the previous call to E02BFF.
On entry,
.
Constraint:
.
-
On entry, .
Constraint: .
-
On entry, , and .
Constraint: .
-
On entry, .
Constraint: .
-
On entry, .
Constraint: .
-
On entry, .
Constraint: .
7 Accuracy
The computed value of
has negligible error in most practical situations. Specifically, this value has an absolute error bounded in modulus by
, where
is the largest in modulus of
,
,
and
, and
is an integer such that
. If
,
,
and
are all of the same sign, then the computed value of
has relative error bounded by
. For full details see
Cox (1978).
No complete error analysis is available for the computation of the derivatives of . However, for most practical purposes the absolute errors in the computed derivatives should be small. Note that this is in comparison to the derivatives of the spline, which may or may not be comparable to the derivatives of the function that has been approximated by the spline.
If using the sorted mode of vectorization, the time required for the first phase to determine the enclosing intervals is approximately proportional to
. The time required to then generate the required permutations and interval information is
if
X is ordered sufficiently, or at worst
if
X is not ordered. The time required by the second phase is then proportional to
.
If using the unsorted mode of vectorization, the time required is proportional to if the enclosing interval numbers are not provided, or if they are provided. However, the repeated calculation of various quantities will typically make this slower than the sorted mode when the ratio of abscissae to knots is high, or the abscissae are densely distributed over a relatively small subset of the intervals of the spline.
Note: the routine does not test all the conditions on the knots given in the description of
LAMDA in
Section 5, since to do this would result in a computation time with a linear dependency upon
instead of
. All the conditions are tested in
E02BAF and
E02BEF, however.
9 Example
This example fits a spline through a set of data points using
E02BEF and then evaluates the spline at a set of supplied abscissae.
9.1 Program Text
Program Text (e02bffe.f90)
9.2 Program Data
Program Data (e02bffe.d)
9.3 Program Results
Program Results (e02bffe.r)