NAG Library Function Document
nag_1d_spline_deriv (e02bcc)
1 Purpose
nag_1d_spline_deriv (e02bcc) evaluates a cubic spline and its first three derivatives from its B-spline representation.
2 Specification
#include <nag.h> |
#include <nage02.h> |
void |
nag_1d_spline_deriv (Nag_DerivType derivs,
double x,
double s[],
Nag_Spline *spline,
NagError *fail) |
|
3 Description
nag_1d_spline_deriv (e02bcc) evaluates the cubic spline
and its first three derivatives at a prescribed argument
. It is assumed that
is represented in terms of its B-spline coefficients
, for
and (augmented) ordered knot set
, for
, (see
nag_1d_spline_fit_knots (e02bac)), i.e.,
Here , is the number of intervals of the spline and denotes the normalized B-spline of degree 3 (order 4) defined upon the knots . The prescribed argument must satisfy .
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.) You must specify whether the value at such a point is required to be the left- or right-hand derivative.
The method employed is based upon:
(i) |
carrying out a binary search for the knot interval containing the argument (see Cox (1978)), |
(ii) |
evaluating the nonzero B-splines of orders 1,2,3 and 4 by recurrence (see Cox (1972) and Cox (1978)), |
(iii) |
computing all derivatives of the B-splines of order 4 by applying a second recurrence to these computed B-spline values (see de Boor (1972)), |
(iv) |
multiplying the 4th-order B-spline values and their derivative by the appropriate B-spline coefficients, and summing, to yield the values of and its derivatives. |
nag_1d_spline_deriv (e02bcc) can be used to compute the values and derivatives of cubic spline fits and interpolants produced by
nag_1d_spline_fit_knots (e02bac),
nag_1d_spline_fit (e02bec) or
nag_1d_spline_interpolant (e01bac).
If only values and not derivatives are required,
nag_1d_spline_evaluate (e02bbc) may be used instead of nag_1d_spline_deriv (e02bcc), which takes about 50% longer than
nag_1d_spline_evaluate (e02bbc).
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 Arguments
- 1:
– Nag_DerivTypeInput
-
On entry:
derivs, of type Nag_DerivType, specifies whether left- or right-hand values of the spline and its derivatives are to be computed (see
Section 3). Left- or right-hand values are formed according to whether
derivs is equal to
or
respectively. If
does not coincide with a knot, the value of
derivs is immaterial. If
, right-hand values are computed, and if
), left-hand values are formed, regardless of the value of
derivs.
Constraint:
or .
- 2:
– doubleInput
-
On entry: the argument at which the cubic spline and its derivatives are to be evaluated.
Constraint:
.
- 3:
– doubleOutput
-
On exit: contains the value of the th derivative of the spline at the argument , for . Note that contains the value of the spline.
- 4:
– Nag_Spline *
-
Pointer to structure of type Nag_Spline with the following members:
- n – 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).
Constraint:
.
- lamda – doubleInput
-
On entry: a pointer to which memory of size must be allocated. 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 .
- c – doubleInput
-
On entry: a pointer to which memory of size must be allocated. holds the coefficient of the B-spline , for .
Under normal usage, the call to nag_1d_spline_deriv (e02bcc) will follow a call to
nag_1d_spline_fit_knots (e02bac),
nag_1d_spline_interpolant (e01bac) or
nag_1d_spline_fit (e02bec). In that case, the structure
spline will have been set up correctly for input to nag_1d_spline_deriv (e02bcc).
- 5:
– NagError *Input/Output
-
The NAG error argument (see
Section 2.7 in How to Use the NAG Library and its Documentation).
6 Error Indicators and Warnings
- NE_ABSCI_OUTSIDE_KNOT_INTVL
-
On entry,
x must satisfy
:
,
,
.
- NE_BAD_PARAM
-
On entry, argument
derivs had an illegal value.
- NE_INT_ARG_LT
-
On entry, must not be less than 8: .
- NE_SPLINE_RANGE_INVALID
-
On entry, the cubic spline range is invalid:
while .
These must satisfy .
7 Accuracy
The computed value of
has negligible error in most practical situations. Specifically, this value has an absolute error bounded in modulus by
machine precision, 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
machine precision. 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.
8 Parallelism and Performance
nag_1d_spline_deriv (e02bcc) is not threaded in any implementation.
The time taken by this function is approximately linear in .
Note: the function does not test all the conditions on the knots given in the description of
in
Section 5, since to do this would result in a computation time approximately linear in
instead of
. All the conditions are tested in
nag_1d_spline_fit_knots (e02bac), however, and the knots returned by
nag_1d_spline_interpolant (e01bac) or
nag_1d_spline_fit (e02bec) will satisfy the conditions.
10 Example
Compute, at the 7 arguments , 1, 2, 3, 4, 5, 6, the left- and right-hand values and first 3 derivatives of the cubic spline defined over the interval having the 6 interior knots , 3, 3, 3, 4, 4, the 8 additional knots 0, 0, 0, 0, 6, 6, 6, 6, and the 10 B-spline coefficients 10, 12, 13, 15, 22, 26, 24, 18, 14, 12.
The input data items (using the notation of
Section 5) comprise the following values in the order indicated:
|
|
|
for |
, |
for |
x |
m values of x |
The example program is written in a general form that will enable the values and derivatives of a cubic spline having an arbitrary number of knots to be evaluated at a set of arbitrary points. Any number of datasets may be supplied.
10.1 Program Text
Program Text (e02bcce.c)
10.2 Program Data
Program Data (e02bcce.d)
10.3 Program Results
Program Results (e02bcce.r)