NAG FL Interface
e02bbf (dim1_​spline_​eval)

1 Purpose

e02bbf evaluates a cubic spline from its B-spline representation.

2 Specification

Fortran Interface
Subroutine e02bbf ( ncap7, lamda, c, x, s, ifail)
Integer, Intent (In) :: ncap7
Integer, Intent (Inout) :: ifail
Real (Kind=nag_wp), Intent (In) :: lamda(ncap7), c(ncap7), x
Real (Kind=nag_wp), Intent (Out) :: s
C Header Interface
#include <nag.h>
void  e02bbf_ (const Integer *ncap7, const double lamda[], const double c[], const double *x, double *s, Integer *ifail)
The routine may be called by the names e02bbf or nagf_fit_dim1_spline_eval.

3 Description

e02bbf evaluates the cubic spline sx at a prescribed argument x from its augmented knot set λi, for i=1,2,,n+7, (see e02baf) and from the coefficients ci, for i=1,2,,qin its B-spline representation
sx=i=1qciNix.  
Here q=n¯+3, where n¯ is the number of intervals of the spline, and Nix denotes the normalized B-spline of degree 3 defined upon the knots λi,λi+1,,λi+4. The prescribed argument x must satisfy λ4xλn¯+4.
It is assumed that λjλj-1, for j=2,3,,n¯+7, and λn¯+4>λ4.
If x is a point at which 4 knots coincide, sx is discontinuous at x; in this case, s contains the value defined as x is approached from the right.
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 and Hayes (1973).
It is expected that a common use of e02bbf will be the evaluation of the cubic spline approximations produced by e02baf. A generalization of e02bbf which also forms the derivative of sx is e02bcf. e02bcf takes about 50% longer than e02bbf.

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: ncap7 Integer Input
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: ncap78.
2: lamdancap7 Real (Kind=nag_wp) array Input
On entry: lamdaj must be set to the value of the jth member of the complete set of knots, λj, for j=1,2,,n¯+7.
Constraint: the lamdaj must be in nondecreasing order with lamdancap7-3> lamda4.
3: cncap7 Real (Kind=nag_wp) array Input
On entry: the coefficient ci of the B-spline Nix, for i=1,2,,n¯+3. The remaining elements of the array are not referenced.
4: x Real (Kind=nag_wp) Input
On entry: the argument x at which the cubic spline is to be evaluated.
Constraint: lamda4xlamdancap7-3.
5: s Real (Kind=nag_wp) Output
On exit: the value of the spline, sx.
6: ifail Integer Input/Output
On entry: ifail must be set to 0, -1 or 1 to set behaviour on detection of an error; these values have no effect when no error is detected.
A value of 0 causes the printing of an error message and program execution will be halted; otherwise program execution continues. A value of -1 means that an error message is printed while a value of 1 means that it is not.
If halting is not appropriate, the value -1 or 1 is recommended. If message printing is undesirable, then the value 1 is recommended. Otherwise, the value 0 is recommended. When the value -1 or 1 is used it is essential to test the value of ifail on exit.
On exit: ifail=0 unless the routine detects an error or a warning has been flagged (see Section 6).

6 Error Indicators and Warnings

If on entry ifail=0 or -1, explanatory error messages are output on the current error message unit (as defined by x04aaf).
Errors or warnings detected by the routine:
ifail=1
On entry, x=value, ncap7=value and lamdancap7-3=value.
Constraint: xlamdancap7-3.
On entry, x=value and lamda4=value.
Constraint: xlamda4.
ifail=2
On entry, ncap7=value.
Constraint: ncap78.
ifail=-99
An unexpected error has been triggered by this routine. Please contact NAG.
See Section 7 in the Introduction to the NAG Library FL Interface for further information.
ifail=-399
Your licence key may have expired or may not have been installed correctly.
See Section 8 in the Introduction to the NAG Library FL Interface for further information.
ifail=-999
Dynamic memory allocation failed.
See Section 9 in the Introduction to the NAG Library FL Interface for further information.

7 Accuracy

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

8 Parallelism and Performance

e02bbf is not threaded in any implementation.

9 Further Comments

The time taken is approximately c×1+0.1×logn¯+7 seconds, where c is a machine-dependent constant.
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 approximately linear in n¯+7 instead of logn¯+7. All the conditions are tested in e02baf, however.

10 Example

Evaluate at nine equally-spaced points in the interval 1.0x9.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 lamda4xlamdan¯+4. The program is self-starting in that any number of datasets may be supplied.

10.1 Program Text

Program Text (e02bbfe.f90)

10.2 Program Data

Program Data (e02bbfe.d)

10.3 Program Results

Program Results (e02bbfe.r)
GnuplotProduced by GNUPLOT 4.6 patchlevel 3 0 1 2 3 4 5 6 7 1 2 3 4 5 6 7 8 9 Cubic Spline x Example Program Evaluation of Cubic Spline Representation gnuplot_plot_1 gnuplot_plot_2 points of evaluation