hide long namesshow long names
hide short namesshow short names
Integer type:  int32  int64  nag_int  show int32  show int32  show int64  show int64  show nag_int  show nag_int

PDF version (NAG web site, 64-bit version, 64-bit version)
Chapter Contents
Chapter Introduction
NAG Toolbox

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 xx-yy 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 (xq,yr,f q , r ) ( x q , y r , f q , r ) , for q = 1,2,,mxq=1,2,,mx and r = 1,2,,myr=1,2,,my. The spline is given in the B-spline representation
mxmy
s(x,y) = cijMi(x)Nj(y),
i = 1j = 1
s(x,y)=i=1mxj=1mycijMi(x)Nj(y),
such that
s(xq,yr) = fq,r,
s(xq,yr)=fq,r,
where Mi(x)Mi(x) and Nj(y)Nj(y) denote normalized cubic B-splines, the former defined on the knots λiλi to λi + 4λi+4 and the latter on the knots μjμj to μj + 4μj+4, and the cijcij 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 Section [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.
Values and derivatives of the computed spline can subsequently be computed by calling nag_fit_2dspline_evalv (e02de), nag_fit_2dspline_evalm (e02df) or nag_fit_2dspline_derivm (e02dh) as described in Section [Evaluation of Computed Spline].

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:     x(mx) – double array
2:     y(my) – double array
mx, the dimension of the array, must satisfy the constraint mx4mx4 and my4my4.
x(q)xq and y(r)yr must contain xqxq, for q = 1,2,,mxq=1,2,,mx, and yryr, for r = 1,2,,myr=1,2,,my, respectively.
Constraints:
  • x(q) < x(q + 1)xq<xq+1, for q = 1,2,,mx1q=1,2,,mx-1;
  • y(r) < y(r + 1)yr<yr+1, for r = 1,2,,my1r=1,2,,my-1.
3:     f(mx × mymx×my) – double array
f(my × (q1) + r)fmy×(q-1)+r must contain fq,rfq,r, for q = 1,2,,mxq=1,2,,mx and r = 1,2,,myr=1,2,,my.

Optional Input Parameters

1:     mx – int64int32nag_int scalar
2:     my – 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 mxmx and mymy respectively, the number of points along the xx and yy axis that define the rectangular grid.
Constraint: mx4mx4 and my4my4.

Input Parameters Omitted from the MATLAB Interface

wrk

Output Parameters

1:     px – int64int32nag_int scalar
2:     py – int64int32nag_int scalar
px and py contain mx + 4mx+4 and my + 4my+4, the total number of knots of the computed spline with respect to the xx and yy variables, respectively.
3:     lamda(mx + 4mx+4) – double array
4:     mu(my + 4my+4) – double array
lamda contains the complete set of knots λiλi associated with the xx variable, i.e., the interior knots lamda(5),lamda(6),,lamda(px4)lamda5,lamda6,,lamdapx-4, as well as the additional knots
lamda(1) = lamda(2) = lamda(3) = lamda(4) = x(1)
lamda1=lamda2=lamda3=lamda4=x1
and
lamda(px3) = lamda(px2) = lamda(px1) = lamda(px) = x(mx)
lamdapx-3=lamdapx-2=lamdapx-1=lamdapx=xmx
needed for the B-spline representation.
5:     c(mx × mymx×my) – double array
The coefficients of the spline interpolant. c(my × (i1) + j)cmy×(i-1)+j contains the coefficient cijcij described in Section [Description].
6:     ifail – int64int32nag_int scalar
ifail = 0ifail=0 unless the function detects an error (see [Error Indicators and Warnings]).

Error Indicators and Warnings

Errors or warnings detected by the function:
  ifail = 1ifail=1
On entry,mx < 4mx<4,
ormy < 4my<4.
  ifail = 2ifail=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 = 3ifail=3
A system of linear equations defining the B-spline coefficients was singular; the problem is too ill-conditioned to permit solution.

Accuracy

The main sources of rounding errors are in steps 22, 33, 66 and 77 of the algorithm described in Section [Outline of Method Used]. It can be shown (see Cox (1975)) that the matrix AxAx formed in step 22 has elements differing relatively from their true values by at most a small multiple of 3ε3ε, where εε is the machine precision. AxAx 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 66 and 77. Thus the complete process is numerically stable.

Further Comments

Timing

The time taken by nag_interp_2d_spline_grid (e01da) is approximately proportional to mxmymxmy.

Outline of Method Used

The process of computing the spline consists of the following steps:
  1. choice of the interior xx-knots λ5λ5, λ6,,λmxλ6,,λmx as λi = xi2λi=xi-2, for i = 5,6,,mxi=5,6,,mx,
  2. formation of the system
    AxE = F,
    AxE=F,
    where AxAx is a band matrix of order mxmx and bandwidth 44, containing in its qqth row the values at xqxq of the B-splines in xx, ff is the mxmx by mymy rectangular matrix of values fq,rfq,r, and EE denotes an mxmx by mymy 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 EE,
  5. choice of the interior yy knots μ5μ5, μ6,,μmyμ6,,μmy as μi = yi2μi=yi-2, for i = 5,6,,myi=5,6,,my,
  6. formation of the system
    AyCT = ET,
    AyCT=ET,
    where AyAy is the counterpart of AxAx for the yy variable, and CC denotes the mxmx by mymy rectangular matrix of values of cijcij,
  7. use of Gaussian elimination to reduce this system to band triangular form,
  8. solution of this triangular system for CTCT and hence CC.
For computational convenience, steps 22 and 33, and likewise steps 66 and 77, are combined so that the formation of AxAx and AyAy 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 (xk,yk) (xk,yk) , for k = 1,2,,mk=1,2,,m, may be obtained in the double array ff (see nag_fit_2dspline_evalv (e02de)), of length at least mm, by the following call:
[ff, ifail] = e02de(x, y, lamda, mu, c);
where M = mM=m and the coordinates xkxk, ykyk are stored in X(k)X(k), Y(k)Y(k). 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 mxmx by mymy rectangular grid of points in the xx-yy plane, which is defined by the xx coordinates stored in X(j)X(j), for j = 1,2,,mxj=1,2,,mx, and the yy coordinates stored in Y(k)Y(k), for k = 1,2,,myk=1,2,,my, returning the results in the double array ff (see nag_fit_2dspline_evalm (e02df)) which is of length at least mx × mymx×my, the following call may be used:
[fg, ifail] = e02df(x, y, lamda, mu, c);
where MX = mxMX=mx, MY = myMY=my. 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 (j,k) (j,k)  is returned in element ( MY × (j1) + k MY×(j-1)+k ) of the array FG.

Example

function nag_interp_2d_spline_grid_example
x = [1;
     1.1;
     1.3;
     1.5;
     1.6;
     1.8;
     2];
y = [0;
     0.1;
     0.4;
     0.7;
     0.9;
     1];
f = [1;
     1.1;
     1.4;
     1.7;
     1.9;
     2;
     1.21;
     1.31;
     1.61;
     1.91;
     2.11;
     2.21;
     1.69;
     1.79;
     2.09;
     2.39;
     2.59;
     2.69;
     2.25;
     2.35;
     2.65;
     2.95;
     3.15;
     3.25;
     2.56;
     2.66;
     2.96;
     3.26;
     3.46;
     3.56;
     3.24;
     3.34;
     3.64;
     3.94;
     4.14;
     4.24;
     4;
     4.1;
     4.4;
     4.7;
     4.9;
     5];
[px, py, lamda, mu, c, ifail] = nag_interp_2d_spline_grid(x, y, f)
 

px =

                   11


py =

                   10


lamda =

    1.0000
    1.0000
    1.0000
    1.0000
    1.3000
    1.5000
    1.6000
    2.0000
    2.0000
    2.0000
    2.0000


mu =

         0
         0
         0
         0
    0.4000
    0.7000
    1.0000
    1.0000
    1.0000
    1.0000


c =

    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


ifail =

                    0


function e01da_example
x = [1;
     1.1;
     1.3;
     1.5;
     1.6;
     1.8;
     2];
y = [0;
     0.1;
     0.4;
     0.7;
     0.9;
     1];
f = [1;
     1.1;
     1.4;
     1.7;
     1.9;
     2;
     1.21;
     1.31;
     1.61;
     1.91;
     2.11;
     2.21;
     1.69;
     1.79;
     2.09;
     2.39;
     2.59;
     2.69;
     2.25;
     2.35;
     2.65;
     2.95;
     3.15;
     3.25;
     2.56;
     2.66;
     2.96;
     3.26;
     3.46;
     3.56;
     3.24;
     3.34;
     3.64;
     3.94;
     4.14;
     4.24;
     4;
     4.1;
     4.4;
     4.7;
     4.9;
     5];
[px, py, lamda, mu, c, ifail] = e01da(x, y, f)
 

px =

                   11


py =

                   10


lamda =

    1.0000
    1.0000
    1.0000
    1.0000
    1.3000
    1.5000
    1.6000
    2.0000
    2.0000
    2.0000
    2.0000


mu =

         0
         0
         0
         0
    0.4000
    0.7000
    1.0000
    1.0000
    1.0000
    1.0000


c =

    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


ifail =

                    0



PDF version (NAG web site, 64-bit version, 64-bit version)
Chapter Contents
Chapter Introduction
NAG Toolbox

© The Numerical Algorithms Group Ltd, Oxford, UK. 2009–2013