NAG Library Function Document
nag_1d_spline_deriv (e02bcc) evaluates a cubic spline and its first three derivatives from its B-spline representation.
||nag_1d_spline_deriv (Nag_DerivType derivs,
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
and (augmented) ordered knot set
, (see nag_1d_spline_fit_knots (e02bac)
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:
||carrying out a binary search for the knot interval containing the argument (see Cox (1978)),
||evaluating the nonzero B-splines of orders 1,2,3 and 4 by recurrence (see Cox (1972) and Cox (1978)),
||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)),
||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)
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
, 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
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
On entry: the argument at which the cubic spline and its derivatives are to be evaluated.
On exit: contains the value of the th derivative of the spline at the argument , for . Note that contains the value of the spline.
– 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).
- 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 .
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).
– NagError *Input/Output
The NAG error argument (see Section 3.6
in the Essential Introduction).
6 Error Indicators and Warnings
On entry, x
On entry, argument derivs
had an illegal value.
On entry, must not be less than 8: .
On entry, the cubic spline range is invalid:
These must satisfy .
The computed value of
has negligible error in most practical situations. Specifically, this value has an absolute error bounded in modulus by machine precision
is the largest in modulus of
is an integer such that
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
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
. 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.
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:
||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)