NAG Library Function Document
nag_2d_spline_interpolant (e01dac)
1 Purpose
nag_2d_spline_interpolant (e01dac) computes a bicubic spline interpolating surface through a set of data values, given on a rectangular grid in the - plane.
2 Specification
#include <nag.h> |
#include <nage01.h> |
void |
nag_2d_spline_interpolant (Integer mx,
Integer my,
const double x[],
const double y[],
const double f[],
Nag_2dSpline *spline,
NagError *fail) |
|
3 Description
nag_2d_spline_interpolant (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.
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
nag_2d_spline_eval (e02dec),
nag_2d_spline_eval_rect (e02dfc) and
nag_2d_spline_deriv_rect (e02dhc) as described in
Section 9.2.
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 Arguments
- 1:
mx – IntegerInput
- 2:
my – 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:
x[mx] – const doubleInput
- 4:
y[my] – const doubleInput
-
On entry: and must contain , for , and , for , respectively.
Constraints:
- , for ;
- , for .
- 5:
f[] – const doubleInput
-
On entry: must contain , for and .
- 6:
spline – 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 nag_2d_spline_interpolant (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:
fail – NagError *Input/Output
-
The NAG error argument (see
Section 3.6 in the Essential Introduction).
6 Error 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:
,
.
7 Accuracy
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.
8 Parallelism and Performance
Not applicable.
The time taken by nag_2d_spline_interpolant (e01dac) is approximately proportional to .
9.1 Outline 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 4, containing in its th row the values at of the B-splines in , is the by rectangular matrix of values , and denotes an by 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 by 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.2 Evaluation 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 nag_2d_spline_interpolant (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 nag_2d_spline_interpolant (e01dac). The result of the spline evaluated at grid point
is returned in element
of the array
fg.
10 Example
This program reads in values of , , for , and , for , followed by values of the ordinates defined at the grid points . It then calls nag_2d_spline_interpolant (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.
10.1 Program Text
Program Text (e01dace.c)
10.2 Program Data
Program Data (e01dace.d)
10.3 Program Results
Program Results (e01dace.r)