hide long namesshow long names
hide short namesshow short names
Integer type:  int32  int64  nag_int  show int32  show int32  show int64  show int64  show nag_int  show nag_int

PDF version (NAG web site, 64-bit version, 64-bit version)
Chapter Contents
Chapter Introduction
NAG Toolbox

NAG Toolbox: nag_fit_1dspline_deriv (e02bc)

Purpose

nag_fit_1dspline_deriv (e02bc) evaluates a cubic spline and its first three derivatives from its B-spline representation.

Syntax

[s, ifail] = e02bc(lamda, c, x, left, 'ncap7', ncap7)
[s, ifail] = nag_fit_1dspline_deriv(lamda, c, x, left, 'ncap7', ncap7)

Description

nag_fit_1dspline_deriv (e02bc) evaluates the cubic spline s(x)s(x) and its first three derivatives at a prescribed argument xx. It is assumed that s(x)s(x) is represented in terms of its B-spline coefficients cici, for i = 1,2,,n + 3i=1,2,,n-+3 and (augmented) ordered knot set λiλi, for i = 1,2,,n + 7i=1,2,,n-+7, (see nag_fit_1dspline_knots (e02ba)), i.e.,
q
s(x) = ciNi(x).
i = 1
s(x) = i=1q ci Ni(x) .
Here q = n + 3q=n-+3, nn- is the number of intervals of the spline and Ni(x)Ni(x) denotes the normalized B-spline of degree 33 (order 44) defined upon the knots λi,λi + 1,,λi + 4λi,λi+1,,λi+4. The prescribed argument xx must satisfy
λ4 x λn + 4 .
λ4 x λ n-+4 .
At a simple knot λiλi (i.e., one satisfying λi1 < λi < λi + 1λi-1<λi<λi+1), 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 x = ux=u where (exactly) rr knots coincide (such a point is termed a knot of multiplicity rr), the values of the derivatives of order 4j4-j, for j = 1,2,,rj=1,2,,r, are in general discontinuous. (Here 1r41r4; r > 4r>4 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 xx (see Cox (1978)),
(ii) evaluating the nonzero B-splines of orders 11, 22, 33 and 44 by recurrence (see Cox (1972) and Cox (1978)),
(iii) computing all derivatives of the B-splines of order 44 by applying a second recurrence to these computed B-spline values (see de Boor (1972)),
(iv) multiplying the fourth-order B-spline values and their derivative by the appropriate B-spline coefficients, and summing, to yield the values of s(x)s(x) and its derivatives.
nag_fit_1dspline_deriv (e02bc) can be used to compute the values and derivatives of cubic spline fits and interpolants produced by nag_fit_1dspline_knots (e02ba).
If only values and not derivatives are required, nag_fit_1dspline_eval (e02bb) may be used instead of nag_fit_1dspline_deriv (e02bc), which takes about 50%50% longer than nag_fit_1dspline_eval (e02bb).

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

Parameters

Compulsory Input Parameters

1:     lamda(ncap7) – double array
ncap7, the dimension of the array, must satisfy the constraint ncap78ncap78.
lamda(j)lamdaj must be set to the value of the jjth member of the complete set of knots, λjλj, for j = 1,2,,n + 7j=1,2,,n-+7.
Constraint: the lamda(j)lamdaj must be in nondecreasing order with
lamda(ncap73) > lamda(4)lamdancap7-3>lamda4.
2:     c(ncap7) – double array
ncap7, the dimension of the array, must satisfy the constraint ncap78ncap78.
The coefficient cici of the B-spline Ni(x)Ni(x), for i = 1,2,,n + 3i=1,2,,n-+3. The remaining elements of the array are not referenced.
3:     x – double scalar
The argument xx at which the cubic spline and its derivatives are to be evaluated.
Constraint: lamda(4)xlamda(ncap73)lamda4xlamdancap7-3.
4:     left – int64int32nag_int scalar
Specifies whether left- or right-hand values of the spline and its derivatives are to be computed (see Section [Description]). Left- or right-hand values are formed according to whether left is equal or not equal to 11.
If xx does not coincide with a knot, the value of left is immaterial.
If x = lamda(4)x=lamda4, right-hand values are computed.
If x = lamda(ncap73)x=lamdancap7-3, left-hand values are formed, regardless of the value of left.

Optional Input Parameters

1:     ncap7 – int64int32nag_int scalar
Default: The dimension of the arrays lamda, c. (An error is raised if these dimensions are not equal.)
n + 7n-+7, where nn- 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 λ4λ4 to λn + 4λn-+4 over which the spline is defined).
Constraint: ncap78ncap78.

Input Parameters Omitted from the MATLAB Interface

None.

Output Parameters

1:     s(44) – double array
s(j)sj contains the value of the (j1)(j-1)th derivative of the spline at the argument xx, for j = 1,2,3,4j=1,2,3,4. Note that s(1)s1 contains the value of the spline.
2:     ifail – int64int32nag_int scalar
ifail = 0ifail=0 unless the function detects an error (see [Error Indicators and Warnings]).

Error Indicators and Warnings

Errors or warnings detected by the function:
  ifail = 1ifail=1
ncap7 < 8ncap7<8, i.e., the number of intervals is not positive.
  ifail = 2ifail=2
Either lamda(4)lamda(ncap73)lamda4lamdancap7-3, i.e., the range over which s(x)s(x) is defined is null or negative in length, or x is an invalid argument, i.e., x < lamda(4)x<lamda4 or x > lamda(ncap73)x>lamdancap7-3.

Accuracy

The computed value of s(x)s(x) has negligible error in most practical situations. Specifically, this value has an absolute error bounded in modulus by 18 × cmax × machine precision18×cmax×machine precision, where cmaxcmax is the largest in modulus of cj,cj + 1,cj + 2cj,cj+1,cj+2 and cj + 3cj+3, and jj is an integer such that λj + 3xλj + 4λj+3xλj+4. If cj,cj + 1,cj + 2cj,cj+1,cj+2 and cj + 3cj+3 are all of the same sign, then the computed value of s(x)s(x) has relative error bounded by 20 × machine precision20×machine precision. For full details see Cox (1978).
No complete error analysis is available for the computation of the derivatives of s(x)s(x). However, for most practical purposes the absolute errors in the computed derivatives should be small.

Further Comments

The time taken is approximately linear in log(n + 7)log(n-+7).
Note:  the function does not test all the conditions on the knots given in the description of lamda in Section [Parameters], since to do this would result in a computation time approximately linear in n + 7n-+7 instead of log(n + 7)log(n-+7). All the conditions are tested in nag_fit_1dspline_knots (e02ba), however.

Example

function nag_fit_1dspline_deriv_example
lamda = [0;
     0;
     0;
     0;
     1;
     3;
     3;
     3;
     4;
     4;
     6;
     6;
     6;
     6];
c = [10;
     12;
     13;
     15;
     22;
     26;
     24;
     18;
     14;
     12;
     0;
     0;
     0;
     0];
x = 0;
left = int64(1);
[s, ifail] = nag_fit_1dspline_deriv(lamda, c, x, left)
 

s =

   10.0000
    6.0000
  -10.0000
   10.6667


ifail =

                    0


function e02bc_example
lamda = [0;
     0;
     0;
     0;
     1;
     3;
     3;
     3;
     4;
     4;
     6;
     6;
     6;
     6];
c = [10;
     12;
     13;
     15;
     22;
     26;
     24;
     18;
     14;
     12;
     0;
     0;
     0;
     0];
x = 0;
left = int64(1);
[s, ifail] = e02bc(lamda, c, x, left)
 

s =

   10.0000
    6.0000
  -10.0000
   10.6667


ifail =

                    0



PDF version (NAG web site, 64-bit version, 64-bit version)
Chapter Contents
Chapter Introduction
NAG Toolbox

© The Numerical Algorithms Group Ltd, Oxford, UK. 2009–2013