E01BAF (PDF version)
E01 Chapter Contents
E01 Chapter Introduction
NAG Library Manual

NAG Library Routine Document

E01BAF

Note:  before using this routine, please read the Users' Note for your implementation to check the interpretation of bold italicised terms and other implementation-dependent details.

 Contents

    1  Purpose
    7  Accuracy

1  Purpose

E01BAF determines a cubic spline interpolant to a given set of data.

2  Specification

SUBROUTINE E01BAF ( M, X, Y, LAMDA, C, LCK, WRK, LWRK, IFAIL)
INTEGER  M, LCK, LWRK, IFAIL
REAL (KIND=nag_wp)  X(M), Y(M), LAMDA(LCK), C(LCK), WRK(LWRK)

3  Description

E01BAF determines a cubic spline sx, defined in the range x1xxm, which interpolates (passes exactly through) the set of data points xi,yi, for i=1,2,,m, where m4 and x1<x2<<xm. Unlike some other spline interpolation algorithms, derivative end conditions are not imposed. The spline interpolant chosen has m-4 interior knots λ5,λ6,,λm, which are set to the values of x3,x4,,xm-2 respectively. This spline is represented in its B-spline form (see Cox (1975)):
sx=i=1mciNix,  
where Nix denotes the normalized B-spline of degree 3, defined upon the knots λi,λi+1,,λi+4, and ci denotes its coefficient, whose value is to be determined by the routine.
The use of B-splines requires eight additional knots λ1, λ2, λ3, λ4, λm+1, λm+2, λm+3 and λm+4 to be specified; E01BAF sets the first four of these to x1 and the last four to xm.
The algorithm for determining the coefficients is as described in Cox (1975) except that QR factorization is used instead of LU decomposition. The implementation of the algorithm involves setting up appropriate information for the related routine E02BAF followed by a call of that routine. (See E02BAF for further details.)
Values of the spline interpolant, or of its derivatives or definite integral, can subsequently be computed as detailed in Section 9.

4  References

Cox M G (1975) An algorithm for spline interpolation J. Inst. Math. Appl. 15 95–108
Cox M G (1977) A survey of numerical methods for data and function approximation The State of the Art in Numerical Analysis (ed D A H Jacobs) 627–668 Academic Press

5  Parameters

1:     M – INTEGERInput
On entry: m, the number of data points.
Constraint: M4.
2:     XM – REAL (KIND=nag_wp) arrayInput
On entry: Xi must be set to xi, the ith data value of the independent variable x, for i=1,2,,m.
Constraint: Xi<Xi+1, for i=1,2,,M-1.
3:     YM – REAL (KIND=nag_wp) arrayInput
On entry: Yi must be set to yi, the ith data value of the dependent variable y, for i=1,2,,m.
4:     LAMDALCK – REAL (KIND=nag_wp) arrayOutput
On exit: the value of λi, the ith knot, for i=1,2,,m+4.
5:     CLCK – REAL (KIND=nag_wp) arrayOutput
On exit: the coefficient ci of the B-spline Nix, for i=1,2,,m. The remaining elements of the array are not used.
6:     LCK – INTEGERInput
On entry: the dimension of the arrays LAMDA and C as declared in the (sub)program from which E01BAF is called.
Constraint: LCKM+4.
7:     WRKLWRK – REAL (KIND=nag_wp) arrayWorkspace
8:     LWRK – INTEGERInput
On entry: the dimension of the array WRK as declared in the (sub)program from which E01BAF is called.
Constraint: LWRK6×M+16.
9:     IFAIL – INTEGERInput/Output
On entry: IFAIL must be set to 0, -1​ or ​1. If you are unfamiliar with this parameter you should refer to Section 3.3 in the Essential Introduction for details.
For environments where it might be inappropriate to halt program execution when an error is detected, the value -1​ or ​1 is recommended. If the output of error messages is undesirable, then the value 1 is recommended. Otherwise, if you are not familiar with this parameter, the recommended value is 0. 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,M<4,
orLCK<M+4,
orLWRK<6×M+16.
IFAIL=2
The X-values fail to satisfy the condition
X1<X2<X3<<XM.
IFAIL=-99
An unexpected error has been triggered by this routine. Please contact NAG.
See Section 3.8 in the Essential Introduction for further information.
IFAIL=-399
Your licence key may have expired or may not have been installed correctly.
See Section 3.7 in the Essential Introduction for further information.
IFAIL=-999
Dynamic memory allocation failed.
See Section 3.6 in the Essential Introduction for further information.

7  Accuracy

The rounding errors incurred are such that the computed spline is an exact interpolant for a slightly perturbed set of ordinates yi+δyi. The ratio of the root-mean-square value of the δyi to that of the yi is no greater than a small multiple of the relative machine precision.

8  Parallelism and Performance

Not applicable.

9  Further Comments

The time taken by E01BAF is approximately proportional to m.
All the xi are used as knot positions except x2 and xm-1. This choice of knots (see Cox (1977)) means that sx is composed of m-3 cubic arcs as follows. If m=4, there is just a single arc space spanning the whole interval x1 to x4. If m5, the first and last arcs span the intervals x1 to x3 and xm-2 to xm respectively. Additionally if m6, the ith arc, for i=2,3,,m-4, spans the interval xi+1 to xi+2.
After the call
CALL E01BAF (M, X, Y, LAMDA, C, LCK, WRK, LWRK, IFAIL)
the following operations may be carried out on the interpolant sx.
The value of sx at x=X can be provided in the real variable S by the call
CALL E02BBF (M+4, LAMDA, C, X, S, IFAIL)
(see E02BBF).
The values of sx and its first three derivatives at x=X can be provided in the real array S of dimension 4, by the call
CALL E02BCF (M+4, LAMDA, C, X, LEFT, S, IFAIL)
(see E02BCF).
Here LEFT must specify whether the left- or right-hand value of the third derivative is required (see E02BCF for details).
The value of the integral of sx over the range x1 to xm can be provided in the real variable DINT by
CALL E02BDF (M+4, LAMDA, C, DINT, IFAIL)
(see E02BDF).

10  Example

This example sets up data from 7 values of the exponential function in the interval 0 to 1. E01BAF is then called to compute a spline interpolant to these data.
The spline is evaluated by E02BBF, at the data points and at points halfway between each adjacent pair of data points, and the spline values and the values of ex are printed out.

10.1  Program Text

Program Text (e01bafe.f90)

10.2  Program Data

None.

10.3  Program Results

Program Results (e01bafe.r)


E01BAF (PDF version)
E01 Chapter Contents
E01 Chapter Introduction
NAG Library Manual

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