NAG Library Function Document

nag_1d_spline_evaluate (e02bbc)

 Contents

    1  Purpose
    7  Accuracy

1
Purpose

nag_1d_spline_evaluate (e02bbc) evaluates a cubic spline from its B-spline representation.

2
Specification

#include <nag.h>
#include <nage02.h>
void  nag_1d_spline_evaluate (double x, double *s, Nag_Spline *spline, NagError *fail)

3
Description

nag_1d_spline_evaluate (e02bbc) evaluates the cubic spline s x  at a prescribed argument x  from its augmented knot set λ i , for i=1,2,, n - + 7, (see nag_1d_spline_fit_knots (e02bac)) and from the coefficients c i , for i=1,2,,q, in its B-spline representation
s x = i=1 q c i N i x  
Here q = n - + 3 , where n -  is the number of intervals of the spline, and N i x  denotes the normalized B-spline of degree 3 defined upon the knots λ i , λ i+1 , , λ i+4 . The prescribed argument x  must satisfy λ 4 x λ n - + 4 .
It is assumed that λ j λ j-1 , for j=2,3,, n - + 7, and λ n - + 4 > λ 4 .
The method employed is that of evaluation by taking convex combinations due to de Boor (1972). For further details of the algorithm and its use see Cox (1972) and Cox (1978).
It is expected that a common use of nag_1d_spline_evaluate (e02bbc) will be the evaluation of the cubic spline approximations produced by nag_1d_spline_fit_knots (e02bac). A generalization of nag_1d_spline_evaluate (e02bbc) which also forms the derivative of s x  is nag_1d_spline_deriv (e02bcc). nag_1d_spline_deriv (e02bcc) 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
Cox M G and Hayes J G (1973) Curve fitting: a guide and suite of algorithms for the non-specialist user NPL Report NAC26 National Physical Laboratory
de Boor C (1972) On calculating with B-splines J. Approx. Theory 6 50–62

5
Arguments

1:     x doubleInput
On entry: the argument x  at which the cubic spline is to be evaluated.
Constraint: splinelamda[3] x splinelamda[splinen-4] .
2:     s double *Output
On exit: the value of the spline, s x .
3:     spline Nag_Spline *
Pointer to structure of type Nag_Spline with the following members:
nIntegerInput
On entry: n - + 7 , where n -  is the number of intervals (one greater than the number of interior knots, i.e., the knots strictly within the range λ 4  to λ n - + 4 ) over which the spline is defined.
Constraint: splinen8 .
lamdadouble *Input
On entry: a pointer to which memory of size splinen must be allocated. splinelamda[j-1]  must be set to the value of the j th member of the complete set of knots, λ j  for j = 1 , 2 , , n - + 7 .
Constraint: the λ j  must be in nondecreasing order with splinelamda[splinen-4] > splinelamda[3] .
cdouble *Input
On entry: a pointer to which memory of size splinen-4  must be allocated. splinec holds the coefficient c i  of the B-spline N i x , for i=1,2,, n - + 3.
Under normal usage, the call to nag_1d_spline_evaluate (e02bbc) 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_evaluate (e02bbc).
4:     fail NagError *Input/Output
The NAG error argument (see Section 3.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 splinelamda[3] x splinelamda[splinen-4] :
splinelamda[3] = value, x=value , splinelamda[value] = value.
In this case s is set arbitrarily to zero.
NE_INT_ARG_LT
On entry, splinen must not be less than 8: splinen=value .

7
Accuracy

The computed value of s x  has negligible error in most practical situations. Specifically, this value has an absolute error bounded in modulus by 18 × c max ×  machine precision, where c max  is the largest in modulus of c j , c j+1 , c j+2  and c j+3 , and j  is an integer such that λ j+3 x λ j+4 . If c j , c j+1 , c j+2  and c j+3  are all of the same sign, then the computed value of s x  has a relative error not exceeding 20 ×  machine precision in modulus. For further details see Cox (1978).

8
Parallelism and Performance

nag_1d_spline_evaluate (e02bbc) is not threaded in any implementation.

9
Further Comments

The time taken by nag_1d_spline_evaluate (e02bbc) is approximately C × 1 + 0.1 × log n - + 7  seconds, where C is a machine-dependent constant.
Note: the function does not test all the conditions on the knots given in the description of splinelamda in Section 5, since to do this would result in a computation time approximately linear in n - + 7  instead of log n - + 7 . 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

Evaluate at 9 equally-spaced points in the interval 1.0 x 9.0  the cubic spline with (augmented) knots 1.0, 1.0, 1.0, 1.0, 3.0, 6.0, 8.0, 9.0, 9.0, 9.0, 9.0 and normalized cubic B-spline coefficients 1.0, 2.0, 4.0, 7.0, 6.0, 4.0, 3.0.
The example program is written in a general form that will enable a cubic spline with n -  intervals, in its normalized cubic B-spline form, to be evaluated at m  equally-spaced points in the interval splinelamda[3] x splinelamda[ n - + 3 ] . The program is self-starting in that any number of datasets may be supplied.

10.1
Program Text

Program Text (e02bbce.c)

10.2
Program Data

Program Data (e02bbce.d)

10.3
Program Results

Program Results (e02bbce.r)

© The Numerical Algorithms Group Ltd, Oxford, UK. 2017