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_fit_2dspline_evalv (e02de)


    1  Purpose
    2  Syntax
    7  Accuracy
    9  Example


nag_fit_2dspline_evalv (e02de) calculates values of a bicubic spline from its B-spline representation.


[ff, ifail] = e02de(x, y, lamda, mu, c, 'm', m, 'px', px, 'py', py)
[ff, ifail] = nag_fit_2dspline_evalv(x, y, lamda, mu, c, 'm', m, 'px', px, 'py', py)


nag_fit_2dspline_evalv (e02de) calculates values of the bicubic spline sx,y at prescribed points xr,yr, for r=1,2,,m, from its augmented knot sets λ and μ and from the coefficients cij, for i=1,2,,px-4 and j=1,2,,py-4, in its B-spline representation
Here 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.
This function may be used to calculate values of a bicubic spline given in the form produced by nag_interp_2d_spline_grid (e01da), nag_fit_2dspline_panel (e02da), nag_fit_2dspline_grid (e02dc) and nag_fit_2dspline_sctr (e02dd). It is derived from the function B2VRE in Anthony et al. (1982).


Anthony G T, Cox M G and Hayes J G (1982) DASL – Data Approximation Subroutine Library National Physical Laboratory
Cox M G (1978) The numerical evaluation of a spline from its B-spline representation J. Inst. Math. Appl. 21 135–143


Compulsory Input Parameters

1:     xm – double array
2:     ym – double array
x and y must contain xr and yr, for r=1,2,,m, respectively. These are the coordinates of the points at which values of the spline are required. The order of the points is immaterial.
Constraint: x and y must satisfy
mu4yrmupy- 3,   r= 1,2,,m.  
The spline representation is not valid outside these intervals.
3:     lamdapx – double array
4:     mupy – double array
lamda and mu must contain the complete sets of knots λ and μ associated with the x and y variables respectively.
Constraint: the knots in each set must be in nondecreasing order, with lamdapx-3>lamda4 and mupy-3>mu4.
5:     cpx-4×py-4 – double array
c py-4 × i-1 +j  must contain the coefficient cij described in Description, for i=1,2,,px-4 and j=1,2,,py-4.

Optional Input Parameters

1:     m int64int32nag_int scalar
Default: the dimension of the arrays x, y. (An error is raised if these dimensions are not equal.)
m, the number of points at which values of the spline are required.
Constraint: m1.
2:     px int64int32nag_int scalar
3:     py int64int32nag_int scalar
Default: For px, the dimension of the array lamda. For py, the dimension of the array mu.
px and py must specify the total number of knots associated with the variables x and y respectively. They are such that px-8 and py-8 are the corresponding numbers of interior knots.
Constraint: px8 and py8.

Output Parameters

1:     ffm – double array
ffr contains the value of the spline at the point xr,yr, for r=1,2,,m.
2:     ifail int64int32nag_int scalar
ifail=0 unless the function detects an error (see Error Indicators and Warnings).

Error Indicators and Warnings

Errors or warnings detected by the function:
On entry,m<1,
On entry, the knots in array lamda, or those in array mu, are not in nondecreasing order, or lamdapx-3lamda4, or mupy-3mu4.
On entry, at least one of the prescribed points xr,yr lies outside the rectangle defined by lamda4, lamdapx-3 and mu4, mupy-3.
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.


The method used to evaluate the B-splines is numerically stable, in the sense that each computed value of sxr,yr can be regarded as the value that would have been obtained in exact arithmetic from slightly perturbed B-spline coefficients. See Cox (1978) for details.

Further Comments

Computation time is approximately proportional to the number of points, m, at which the evaluation is required.


This program reads in knot sets lamda1,,lamdapx and mu1,,mupy, and a set of bicubic spline coefficients cij. Following these are a value for m and the coordinates xr,yr, for r=1,2,,m, at which the spline is to be evaluated.
function e02de_example

fprintf('e02de example results\n\n');

% Spline knots and coefficients
lamda = [1    1     1     1     1.3   1.5   1.6   2     2     2     2];
mu    = [0    0     0     0     0.4   0.7   1     1     1     1];
c = [1      1.2    1.5833 2.1433 2.8667 3.4667 4;     
     1.1333 1.3333 1.7167 2.2767 3      3.6    4.1333;
     1.3667 1.5667 1.95   2.51   3.2333 3.8333 4.3667;
     1.7    1.9    2.2833 2.8433 3.5667 4.1667 4.7;   
     1.9    2.1    2.4833 3.0433 3.7667 4.3667 4.9;   
     2      2.2    2.5833 3.1433 3.8667 4.4667 5];

% Evaluate spline at set of points for displaying

x     = [1    1.1   1.5   1.6   1.9   1.9   2];
y     = [0    0.1   0.7   0.4   0.3   0.8   1];

[ff, ifail] = e02de( ...
                     x, y, lamda, mu, c);

fprintf('        x          y          fit\n');
fprintf('%11.3f%11.3f%11.3f\n',[x; y; ff']);

% Evaluate spline on mesh for figure
mx = [1:0.05:2];
my = [0:0.05:1];
for i = 1:21
  xx(1:21) = mx(i);
  [ff(1:21,i), ifail] = e02de( ...
                               xx, my, lamda, mu, c);
fig1 = figure;
title('Least-squares bi-cubic spline surface');

e02de example results

        x          y          fit
      1.000      0.000      1.000
      1.100      0.100      1.310
      1.500      0.700      2.950
      1.600      0.400      2.960
      1.900      0.300      3.910
      1.900      0.800      4.410
      2.000      1.000      5.000

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–2015