The function may be called by the names: e01dac, nag_interp_dim2_spline_grid or nag_2d_spline_interpolant.
3Description
e01dac determines a bicubic spline interpolant to the set of data points , for and . The spline is given in the B-spline representation
such that
where and denote normalized cubic B-splines, the former defined on the knots to and the latter on the knots to , and the are the spline coefficients. These knots, as well as the coefficients, are determined by the function, which is derived from the routine B2IRE in Anthony et al. (1982). The method used is described in Section 9.1.
Values and derivatives of the computed spline can subsequently be computed by calling e02dec,e02dfcande02dhc as described in Section 9.2.
4References
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. Theory6 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
5Arguments
1: – IntegerInput
2: – IntegerInput
On entry: mx and my must specify and respectively, the number of points along the and axis that define the rectangular grid.
Constraint:
and .
3: – const doubleInput
4: – const doubleInput
On entry: and must contain , for , and , for , respectively.
Constraints:
, for ;
, for .
5: – const doubleInput
On entry: must contain , for and .
6: – Nag_2dSpline *
Pointer to structure of type Nag_2dSpline with the following members:
nx – IntegerOutput
ny – IntegerOutput
On exit: and contain and , the total number of knots of the computed spline with respect to the and variables, respectively.
lamda – double *Output
On exit: the pointer to which memory of size is internally allocated. contains the complete set of knots associated with the variable, i.e., the interior knots , , , , as well as the additional knots and needed for the B-spline representation.
mu – double *Output
On exit: the pointer to which memory of size is internally allocated. contains the corresponding complete set of knots associated with the variable.
c – double *Output
On exit: the pointer to which memory of size is internally allocated. holds the coefficients of the spline interpolant. contains the coefficient described in Section 3.
Note that when the information contained in the pointers , and is no longer of use, or before a new call to e01dac with the same spline, you should free these pointers using the NAG macro NAG_FREE. This storage will not have been allocated if this function returns with NE_NOERROR.
7: – NagError *Input/Output
The NAG error argument (see Section 7 in the Introduction to the NAG Library CL Interface).
6Error Indicators and Warnings
NE_ALLOC_FAIL
Dynamic memory allocation failed.
NE_DATA_ILL_CONDITIONED
An intermediate set of linear equations is singular, the data is too ill-conditioned to compute B-spline coefficients.
NE_INT_ARG_LT
On entry, .
Constraint: .
On entry, .
Constraint: .
NE_NOT_STRICTLY_INCREASING
The sequence x is not strictly increasing: , .
The sequence y is not strictly increasing: , .
7Accuracy
The main sources of rounding errors are in steps 1, 3, 6 and 7 of the algorithm described in Section 9.1. It can be shown (Cox (1975)) that the matrix formed in step 2 has elements differing relatively from their true values by at most a small multiple of , where is the machine precision. 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.
8Parallelism and Performance
Background information to multithreading can be found in the Multithreading documentation.
e01dac is not threaded in any implementation.
9Further Comments
The time taken by e01dac is approximately proportional to .
9.1Outline of Method Used
The process of computing the spline consists of the following steps:
1.choice of the interior -knots , as , for ,
2.formation of the system
where is a band matrix of order and bandwidth , containing in its th row the values at of the B-splines in , is the rectangular matrix of values , and denotes an 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 ,
5.choice of the interior knots , as , for ,
6.formation of the system
where is the counterpart of for the variable, and denotes the rectangular matrix of values of ,
7.use of Gaussian elimination to reduce this system to band triangular form,
8.solution of this triangular system for and hence .
For computational convenience, steps 2 and 3, and likewise steps 6 and 7, are combined so that the formation of and and the reductions to triangular form are carried out one row at a time.
9.2Evaluation of Computed Spline
The values of the computed spline at the points , for , may be obtained in the array ff, of length at least n, by the following call:
e02dec (n, tx, ty, ff, &spline, &fail)
where spline is a structure of type Nag_2dSpline which is the output argument of e01dac.
To evaluate the computed spline on a kx by ky rectangular grid of points in the - plane, which is defined by the coordinates stored in , for , and the coordinates stored in , for , returning the results in the array fg which is of length at least , the following call may be used:
e02dfc (kx, ky, tx, ty, fg, &spline, &fail)
where spline is a structure of type Nag_2dSpline which is the output argument of e01dac. The result of the spline evaluated at grid point is returned in element of the array fg.
10Example
This program reads in values of , , for , and , for , followed by values of the ordinates defined at the grid points . It then calls e01dac 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.