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

NAG Library Routine Document

E01DAF

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

E01DAF computes a bicubic spline interpolating surface through a set of data values, given on a rectangular grid in the x-y plane.

2  Specification

SUBROUTINE E01DAF ( MX, MY, X, Y, F, PX, PY, LAMDA, MU, C, WRK, IFAIL)
INTEGER  MX, MY, PX, PY, IFAIL
REAL (KIND=nag_wp)  X(MX), Y(MY), F(MX*MY), LAMDA(MX+4), MU(MY+4), C(MX*MY), WRK((MX+6)*(MY+6))

3  Description

E01DAF determines a bicubic spline interpolant to the set of data points x q , y r , f q , r , for q=1,2,,mx and r=1,2,,my. The spline is given in the B-spline representation
sx,y=i=1mxj=1mycijMixNjy,  
such that
sxq,yr=fq,r,  
where Mix and Njy denote normalized cubic B-splines, the former defined on the knots λi to λi+4 and the latter on the knots μj to μj+4, and the cij are the spline coefficients. These knots, as well as the coefficients, are determined by the routine, which is derived from the routine B2IRE in Anthony et al. (1982). The method used is described in Section 9.2.
For further information on splines, see Hayes and Halliday (1974) for bicubic splines and de Boor (1972) for normalized B-splines.
Values and derivatives of the computed spline can subsequently be computed by calling E02DEF, E02DFF or E02DHF as described in Section 9.3.

4  References

Anthony G T, Cox M G and Hayes J G (1982) DASL – Data Approximation Subroutine Library National Physical Laboratory
Cox M G (1975) An algorithm for spline interpolation J. Inst. Math. Appl. 15 95–108
de Boor C (1972) On calculating with B-splines J. Approx. Theory 6 50–62
Hayes J G and Halliday J (1974) The least squares fitting of cubic spline surfaces to general data sets J. Inst. Math. Appl. 14 89–103

5  Parameters

1:     MX – INTEGERInput
2:     MY – INTEGERInput
On entry: MX and MY must specify mx and my respectively, the number of points along the x and y axis that define the rectangular grid.
Constraint: MX4 and MY4.
3:     XMX – REAL (KIND=nag_wp) arrayInput
4:     YMY – REAL (KIND=nag_wp) arrayInput
On entry: Xq and Yr must contain xq, for q=1,2,,mx, and yr, for r=1,2,,my, respectively.
Constraints:
  • Xq<Xq+1, for q=1,2,,mx-1;
  • Yr<Yr+1, for r=1,2,,my-1.
5:     FMX×MY – REAL (KIND=nag_wp) arrayInput
On entry: Fmy×q-1+r must contain fq,r, for q=1,2,,mx and r=1,2,,my.
6:     PX – INTEGEROutput
7:     PY – INTEGEROutput
On exit: PX and PY contain mx+4 and my+4, the total number of knots of the computed spline with respect to the x and y variables, respectively.
8:     LAMDAMX+4 – REAL (KIND=nag_wp) arrayOutput
9:     MUMY+4 – REAL (KIND=nag_wp) arrayOutput
On exit: LAMDA contains the complete set of knots λi associated with the x variable, i.e., the interior knots LAMDA5,LAMDA6,,LAMDAPX-4, as well as the additional knots
LAMDA1=LAMDA2=LAMDA3=LAMDA4=X1  
and
LAMDAPX-3=LAMDAPX-2=LAMDAPX-1=LAMDAPX=XMX  
needed for the B-spline representation.
10:   CMX×MY – REAL (KIND=nag_wp) arrayOutput
On exit: the coefficients of the spline interpolant. Cmy×i-1+j contains the coefficient cij described in Section 3.
11:   WRKMX+6×MY+6 – REAL (KIND=nag_wp) arrayWorkspace
12:   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,MX<4,
orMY<4.
IFAIL=2
On entry, either the values in the X array or the values in the Y array are not in increasing order if not already there.
IFAIL=3
A system of linear equations defining the B-spline coefficients was singular; the problem is too ill-conditioned to permit solution.
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 main sources of rounding errors are in steps 2, 3, 6 and 7 of the algorithm described in Section 9.2. It can be shown (see Cox (1975)) that the matrix Ax formed in step 2 has elements differing relatively from their true values by at most a small multiple of 3ε, where ε is the machine precision. Ax is ‘totally positive’, and a linear system with such a coefficient matrix can be solved quite safely by elimination without pivoting. Similar comments apply to steps 6 and 7. Thus the complete process is numerically stable.

8  Parallelism and Performance

E01DAF is not threaded by NAG in any implementation.
E01DAF makes calls to BLAS and/or LAPACK routines, which may be threaded within the vendor library used by this implementation. Consult the documentation for the vendor library for further information.
Please consult the X06 Chapter Introduction for information on how to control and interrogate the OpenMP environment used within this routine. Please also consult the Users' Note for your implementation for any additional implementation-specific information.

9  Further Comments

9.1  Timing

The time taken by E01DAF is approximately proportional to mxmy.

9.2  Outline of Method Used

The process of computing the spline consists of the following steps:
1. choice of the interior x-knots λ5, λ6,,λmx as λi=xi-2, for i=5,6,,mx,
2. formation of the system
AxE=F,  
where Ax is a band matrix of order mx and bandwidth 4, containing in its qth row the values at xq of the B-splines in x, F is the mx by my rectangular matrix of values fq,r, and E denotes an mx by my rectangular matrix of intermediate coefficients,
3. use of Gaussian elimination to reduce this system to band triangular form,
4. solution of this triangular system for E,
5. choice of the interior y knots μ5, μ6,,μmy as μi=yi-2, for i=5,6,,my,
6. formation of the system
AyCT=ET,  
where Ay is the counterpart of Ax for the y variable, and C denotes the mx by my rectangular matrix of values of cij,
7. use of Gaussian elimination to reduce this system to band triangular form,
8. solution of this triangular system for CT and hence C.
For computational convenience, steps 2 and 3, and likewise steps 6 and 7, are combined so that the formation of Ax and Ay and the reductions to triangular form are carried out one row at a time.

9.3  Evaluation of Computed Spline

The values of the computed spline at the points xk,yk , for k=1,2,,m, may be obtained in the real array FF (see E02DEF), of length at least m, by the following call:
IFAIL = 0
CALL E02DEF(M,PX,PY,X,Y,LAMDA,MU,C,FF,WRK,IWRK,IFAIL)
where M=m and the coordinates xk, yk are stored in Xk, Yk. PX and PY, LAMDA, MU and C have the same values as PX and PY LAMDA, MU and C output from E01DAF. WRK is a real workspace array of length at least PY, and IWRK is an integer workspace array of length at least PY-4. (See E02DEF.)
To evaluate the computed spline on an mx by my rectangular grid of points in the x-y plane, which is defined by the x coordinates stored in Xj, for j=1,2,,mx, and the y coordinates stored in Yk, for k=1,2,,my, returning the results in the real array FF (see E02DFF) which is of length at least MX×MY, the following call may be used:
 IFAIL = 0
 CALL E02DFF(MX,MY,PX,PY,X,Y,LAMDA,MU,C,FG,WRK,LWRK,
*            IWRK,LIWRK,IFAIL)
where MX=mx, MY=my. PX and PY, LAMDA, MU and C have the same values as PX, PY, LAMDA, MU and C output from E01DAF. WRK is a real workspace array of length at least LWRK = minnwrk1,nwrk2 , for nwrk1 = MX × 4 + PX , nwrk2 = MY × 4 + PY , and IWRK is an integer workspace array of length at least LIWRK = MY + PY - 4  if nwrk1 > nwrk2 , or MX + PX - 4  otherwise.
The result of the spline evaluated at grid point j,k  is returned in element ( MY×j-1+k ) of the array FG.

10  Example

This example reads in values of mx, xq, for q=1,2,,mx, my and yr, for r=1,2,,my, followed by values of the ordinates fq,r defined at the grid points xq,yr.
It then calls E01DAF to compute a bicubic spline interpolant of the data values, and prints the values of the knots and B-spline coefficients. Finally it evaluates the spline at a small sample of points on a rectangular grid.

10.1  Program Text

Program Text (e01dafe.f90)

10.2  Program Data

Program Data (e01dafe.d)

10.3  Program Results

Program Results (e01dafe.r)


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

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