PDF version (NAG web site
, 64-bit version, 64-bit version)
NAG Toolbox: nag_interp_2d_spline_grid (e01da)
Purpose
nag_interp_2d_spline_grid (e01da) computes a bicubic spline interpolating surface through a set of data values, given on a rectangular grid in the - plane.
Syntax
[
px,
py,
lamda,
mu,
c,
ifail] = e01da(
x,
y,
f, 'mx',
mx, 'my',
my)
[
px,
py,
lamda,
mu,
c,
ifail] = nag_interp_2d_spline_grid(
x,
y,
f, 'mx',
mx, 'my',
my)
Description
nag_interp_2d_spline_grid (e01da) 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 function B2IRE in
Anthony et al. (1982). The method used is described in
Outline of Method Used.
For further information on splines, see
Hayes and Halliday (1974) for bicubic splines and
de Boor (1972) for normalized B-splines.
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
Parameters
Compulsory Input Parameters
- 1:
– double array
- 2:
– double array
-
and must contain , for , and
, for , respectively.
Constraints:
- , for ;
- , for .
- 3:
– double array
-
must contain , for and .
Optional Input Parameters
- 1:
– int64int32nag_int scalar
- 2:
– int64int32nag_int scalar
-
Default:
the dimension of the arrays
x,
y. (An error is raised if these dimensions are not equal.)
mx and
my must specify
and
respectively, the number of points along the
and
axis that define the rectangular grid.
Constraint:
and .
Output Parameters
- 1:
– int64int32nag_int scalar
- 2:
– int64int32nag_int scalar
-
px and
py contain
and
, the total number of knots of the computed spline with respect to the
and
variables, respectively.
- 3:
– double array
- 4:
– double array
-
lamda 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.
- 5:
– double array
-
The coefficients of the spline interpolant.
contains the coefficient
described in
Description.
- 6:
– int64int32nag_int scalar
unless the function detects an error (see
Error Indicators and Warnings).
Error Indicators and Warnings
Errors or warnings detected by the function:
-
-
-
-
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.
-
-
A system of linear equations defining the B-spline coefficients was singular; the problem is too ill-conditioned to permit solution.
-
An unexpected error has been triggered by this routine. Please
contact
NAG.
-
Your licence key may have expired or may not have been installed correctly.
-
Dynamic memory allocation failed.
Accuracy
The main sources of rounding errors are in steps
,
,
and
of the algorithm described in
Outline of Method Used. It can be shown (see
Cox (1975)) that the matrix
formed in step
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
and
. Thus the complete process is numerically stable.
Further Comments
Timing
The time taken by nag_interp_2d_spline_grid (e01da) is approximately proportional to .
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 , 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 and , and likewise steps and , are combined so that the formation of and and the reductions to triangular form are carried out one row at a time.
Evaluation of Computed Spline
The values of the computed spline at the points
, for
, may be obtained in the double array
ff (see
nag_fit_2dspline_evalv (e02de)), of length at least
, by the following call:
[ff, ifail] = e02de(x, y, lamda, mu, c);
where
and the coordinates
,
are stored in
,
.
LAMDA,
MU and
C have the same values as
lamda,
mu and
c output from
nag_interp_2d_spline_grid (e01da).
(See
nag_fit_2dspline_evalv (e02de).)
To evaluate the computed spline on an
by
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 double array
ff (see
nag_fit_2dspline_evalm (e02df)) which is of length at least
, the following call may be used:
[fg, ifail] = e02df(x, y, lamda, mu, c);
where
,
.
LAMDA,
MU and
C have the same values as
lamda,
mu and
c output from
nag_interp_2d_spline_grid (e01da).
The result of the spline evaluated at grid point is returned in element () of the array FG.
Example
This example reads in values of , , for , and , for , followed by values of the ordinates defined at the grid points .
It then calls nag_interp_2d_spline_grid (e01da) 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.
Open in the MATLAB editor:
e01da_example
function e01da_example
fprintf('e01da example results\n\n');
x = [1.0 1.10 1.30 1.50 1.60 1.80 2.0];
f = [1.0 1.21 1.69 2.25 2.56 3.24 4.0;
1.1 1.31 1.79 2.35 2.66 3.34 4.1;
1.4 1.61 2.09 2.65 2.96 3.64 4.4;
1.7 1.91 2.39 2.95 3.26 3.94 4.7;
1.9 2.11 2.59 3.15 3.46 4.14 4.9;
2.0 2.21 2.69 3.25 3.56 4.24 5.0];
y = [0.0;
0.1;
0.4;
0.7;
0.9;
1.0];
[px, py, lamda, mu, c, ifail] = e01da( ...
x, y, f);
fprintf('\n i knot lamda(i) j knot mu(j)\n');
j = 4:min(px,py)-3;
fprintf('%16d%12.4f%11d%12.4f\n',[j' lamda(j) j' mu(j)]');
if (px>py);
j = py-2:px-3;
fprintf('%16d%12.4f\n',[j' lamda(j)]');
elseif (px<py);
j = px-2:py-3;
fprintf('%16d%12.4f\n',[j' mu(j)]')
end
c = reshape(c, size(f'));
fprintf('\n');
disp('The B-Spline coefficients:');
disp(c');
dx = (x(end)-x(1))/5;
dy = (y(end)-y(1))/5;
tx = [x(1):dx:x(end)];
ty = [y(1):dy:y(end)]';
[ff, ifail] = e02df( ...
tx, ty, lamda, mu, c);
ff = reshape(ff,[6,6]);
matrix = 'General';
diag = 'Non-unit';
format = 'F8.3';
title = 'Spline evaluated on a regular mesh (x across, y down):';
chlab = 'Character';
rlabs = cellstr(num2str(tx'));
clabs = cellstr(num2str(ty));
ncols = int64(80);
indent = int64(0);
[ifail] = x04cb( ...
matrix, diag, ff, format, title, chlab, ...
rlabs, chlab, clabs, ncols, indent);
e01da example results
i knot lamda(i) j knot mu(j)
4 1.0000 4 0.0000
5 1.0000 5 0.0000
6 2.0000 6 1.0000
7 2.0000 7 1.0000
8 2.0000
The B-Spline coefficients:
1.0000 1.1333 1.3667 1.7000 1.9000 2.0000 1.2000
1.3333 1.5667 1.9000 2.1000 2.2000 1.5833 1.7167
1.9500 2.2833 2.4833 2.5833 2.1433 2.2767 2.5100
2.8433 3.0433 3.1433 2.8667 3.0000 3.2333 3.5667
3.7667 3.8667 3.4667 3.6000 3.8333 4.1667 4.3667
4.4667 4.0000 4.1333 4.3667 4.7000 4.9000 5.0000
Spline evaluated on a regular mesh (x across, y down):
0 0.2 0.4 0.6 0.8 1
1 1.000 1.440 1.960 2.560 3.240 4.000
1.2 1.200 1.640 2.160 2.760 3.440 4.200
1.4 1.400 1.840 2.360 2.960 3.640 4.400
1.6 1.600 2.040 2.560 3.160 3.840 4.600
1.8 1.800 2.240 2.760 3.360 4.040 4.800
2 2.000 2.440 2.960 3.560 4.240 5.000
PDF version (NAG web site
, 64-bit version, 64-bit version)
© The Numerical Algorithms Group Ltd, Oxford, UK. 2009–2015