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_derivm (e02dh)

 Contents

    1  Purpose
    2  Syntax
    7  Accuracy
    9  Example

Purpose

nag_fit_2dspline_derivm (e02dh) computes the partial derivative (of order νx, νy), of a bicubic spline approximation to a set of data values, from its B-spline representation, at points on a rectangular grid in the x-y plane. This function may be used to calculate derivatives 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).

Syntax

[z, ifail] = e02dh(x, y, lamda, mu, c, nux, nuy, 'mx', mx, 'my', my, 'px', px, 'py', py)
[z, ifail] = nag_fit_2dspline_derivm(x, y, lamda, mu, c, nux, nuy, 'mx', mx, 'my', my, 'px', px, 'py', py)

Description

nag_fit_2dspline_derivm (e02dh) determines the partial derivative νx + νy x νx y νy  of a smooth bicubic spline approximation sx,y at the set of data points xq,yr.
The spline is given in the B-spline representation
sx,y = i=1 nx-4 j=1 ny-4 cij Mix Njy , (1)
where 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, with nx and ny the total numbers of knots of the computed spline with respect to the x and y variables respectively. For further details, see Hayes and Halliday (1974) for bicubic splines and de Boor (1972) for normalized B-splines. This function is suitable for B-spline representations returned by nag_interp_2d_spline_grid (e01da), nag_fit_2dspline_panel (e02da), nag_fit_2dspline_grid (e02dc) and nag_fit_2dspline_sctr (e02dd).
The partial derivatives can be up to order 2 in each direction; thus the highest mixed derivative available is 4 x2 y2 .
The points in the grid are defined by coordinates xq, for q=1,2,,mx, along the x axis, and coordinates yr, for r=1,2,,my, along the y axis.

References

de Boor C (1972) On calculating with B-splines J. Approx. Theory 6 50–62
Dierckx P (1981) An improved algorithm for curve fitting with spline functions Report TW54 Department of Computer Science, Katholieke Univerciteit Leuven
Dierckx P (1982) A fast algorithm for smoothing data on a rectangular grid while using spline functions SIAM J. Numer. Anal. 19 1286–1304
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
Reinsch C H (1967) Smoothing by spline functions Numer. Math. 10 177–183

Parameters

Compulsory Input Parameters

1:     xmx – double array
xq must be set to xq, the x coordinate of the qth grid point along the x axis, for q=1,2,,mx, on which values of the partial derivative are sought.
Constraint: x1<x2<<xmx.
2:     ymy – double array
yr must be set to yr, the y coordinate of the rth grid point along the y axis, for r=1,2,,my on which values of the partial derivative are sought.
Constraint: y1<y2<<ymy.
3:     lamdapx – double array
Contains the position of the knots in the x-direction of the bicubic spline approximation to be differentiated, e.g., lamda as returned by nag_fit_2dspline_grid (e02dc).
4:     mupy – double array
Contains the position of the knots in the y-direction of the bicubic spline approximation to be differentiated, e.g., mu as returned by nag_fit_2dspline_grid (e02dc).
5:     cpx-4×py-4 – double array
The coefficients of the bicubic spline approximation to be differentiated, e.g., c as returned by nag_fit_2dspline_grid (e02dc).
6:     nux int64int32nag_int scalar
Specifies the order, νx of the partial derivative in the x-direction.
Constraint: 0nux2.
7:     nuy int64int32nag_int scalar
Specifies the order, νy of the partial derivative in the y-direction.
Constraint: 0nuy2.

Optional Input Parameters

1:     mx int64int32nag_int scalar
Default: the dimension of the array x.
mx, the number of grid points along the x axis.
Constraint: mx1.
2:     my int64int32nag_int scalar
Default: the dimension of the array y.
my, the number of grid points along the y axis.
Constraint: my1.
3:     px int64int32nag_int scalar
Default: the dimension of the array lamda.
The total number of knots in the x-direction of the bicubic spline approximation, e.g., the value nx as returned by nag_fit_2dspline_grid (e02dc).
4:     py int64int32nag_int scalar
Default: the dimension of the array mu.
The total number of knots in the y-direction of the bicubic spline approximation, e.g., the value ny as returned by nag_fit_2dspline_grid (e02dc).

Output Parameters

1:     zmx×my – double array
zmy×q-1+r contains the derivative νx+νy xνx yνy s xq,yr , for q=1,2,,mx and r=1,2,,my.
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:
   ifail=1
Constraint: 0nux2.
   ifail=2
Constraint: 0nuy2.
   ifail=3
Constraint: mx1.
   ifail=4
Constraint: my1.
   ifail=5
Constraint: xi-1xi, for i=2,3,,mx.
   ifail=6
Constraint: yi-1yi, for i=2,3,,my.
   ifail=-99
An unexpected error has been triggered by this routine. Please contact NAG.
   ifail=-399
Your licence key may have expired or may not have been installed correctly.
   ifail=-999
Dynamic memory allocation failed.

Accuracy

On successful exit, the partial derivatives on the given mesh are accurate to machine precision with respect to the supplied bicubic spline. Please refer to Accuracy in nag_interp_2d_spline_grid (e01da), nag_fit_2dspline_panel (e02da), nag_fit_2dspline_grid (e02dc) and nag_fit_2dspline_sctr (e02dd) of the function document for the respective function which calculated the spline approximant for details on the accuracy of that approximation.

Further Comments

None.

Example

This example reads in values of mx, my, xq, for q=1,2,,mx, and yr, for r=1,2,,my, followed by values of the ordinates fq,r defined at the grid points xq,yr. It then calls nag_fit_2dspline_grid (e02dc) to compute a bicubic spline approximation for one specified value of S. Finally it evaluates the spline and its first x derivative at a small sample of points on a rectangular grid by calling nag_fit_2dspline_derivm (e02dh).
function e02dh_example


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

mx = 11;
my = 9;
start = 'C';
x = [0:0.5:5];
y = [0:0.5:4];
% f = (x+1)*cosy + noise 
f = [ 1.0000, 0.88758, 0.54030, 0.070737,-0.41515, ...
             -0.80114,-0.97999,-0.93446, -0.65664, ...
      1.5000, 1.3564,  0.82045, 0.10611, -0.62422, ...
             -1.2317, -1.4850, -1.3047,  -0.98547, ...
      2.0600, 1.7552,  1.0806,  0.15147, -0.83229, ...
             -1.6023, -1.9700, -1.8729,  -1.4073,  ...
      2.5700, 2.1240,  1.3508,  0.17684, -1.0404,  ...
             -2.0029, -2.4750, -2.3511,  -1.6741,  ...
      3.0000, 2.6427,  1.6309,  0.21221, -1.2484,  ...
             -2.2034, -2.9700, -2.8094,  -1.9809, ...
      3.5000, 3.1715,  1.8611,  0.24458, -1.4565, ...
             -2.8640, -3.2650, -3.2776,  -2.2878, ...
      4.0400, 3.5103,  2.0612,  0.28595, -1.6946, ...
             -3.2046, -3.9600, -3.7958,  -2.6146, ...
      4.5000, 3.9391,  2.4314,  0.31632, -1.8627, ...
             -3.6351, -4.4550, -4.2141,  -2.9314, ...
      5.0400, 4.3879,  2.7515,  0.35369, -2.0707, ...
             -4.0057, -4.9700, -4.6823,  -3.2382, ...
      5.5050, 4.8367,  2.9717,  0.38505, -2.2888, ...
             -4.4033, -5.4450, -5.1405,  -3.5950, ...
      6.0000, 5.2755,  3.2418,  0.42442, -2.4769, ...
             -4.8169, -5.9300, -5.6387,  -3.9319];
s = 0.1;
ngx = 6;
xlo = 0;
xhi = 5;
ngy = 5;
ylo = 0;
yhi = 4;

nxest = mx + 4;
nyest = my + 4;
lamda = zeros(nxest, 1);
mu    = zeros(nyest, 1);
wrk   = zeros(4*(mx+my) + 11*(nxest+nyest) + nxest*my + max(my,nxest) + 54, 1);
iwrk  = zeros(3 + mx + my + nxest + nyest, 1, 'int64');

% Determine the spline approximation
[nx, lamda, ny, mu, c, fp, wrk, iwrk, ifail] = ...
e02dc( ...
       start, x, y, f, s, int64(0), lamda, int64(0), mu, wrk, iwrk);

fprintf('\nSpline fit used smoothing factor S = %13.4e.\n', s);
fprintf('Number of knots in each direction  = %d, %d\n', nx, ny);
fprintf('\nSum of squared residuals           = %13.4e.\n', fp);

% Evaluate the spline derivative on a different rectangular grid with
% ngx*ngy points over the domain (xlo to xhi) x (ylo to yhi).
gridx = [xlo:(xhi-xlo)/(ngx-1):xhi];
gridy = [ylo:(yhi-ylo)/(ngy-1):yhi];

% Evaluate spline (nux=nuy=0)
nux = int64(0);
nuy = int64(0);
[z, ifail] = e02dh( ...
                    gridx, gridy, lamda(1:nx), mu(1:ny), c, nux, nuy);

nux = int64(1);
% Evaluate spline partial derivative of order (nux, nuy)
[zder, ifail] = e02dh( ...
                       gridx, gridy, lamda(1:nx), mu(1:ny), c, nux, nuy);

% Spline partial derivatives to evaluate have order nux,nuy.
fprintf('\nDerivative of spline has order nux, nuy = %d, %d.\n\n', nux, nuy);

% Print the spline evaluations
rlabs = cell(size(gridy));
for i = 1:ngy
  rlabs{i} = num2str(gridy(i));
end
clabs = cell(size(gridx));
for i = 1:ngx
  clabs{i} = num2str(gridx(i));
end
title = 'Spline evaluated on X-Y grid (X across, Y down):';
[ifail] = x04cb('G', 'N', reshape(z, ngy, ngx), 'F8.3', title, ...
                'C', rlabs, 'C', clabs, int64(80), int64(0));
fprintf('\n');
title = 'Spline derivative evaluated on X-Y grid:';
[ifail] = x04cb('G', 'N', reshape(zder, ngy, ngx), 'F8.3', title, ...
                'C', rlabs, 'C', clabs, int64(80), int64(0));


e02dh example results


Spline fit used smoothing factor S =    1.0000e-01.
Number of knots in each direction  = 10, 13

Sum of squared residuals           =    1.0004e-01.

Derivative of spline has order nux, nuy = 1, 0.

 Spline evaluated on X-Y grid (X across, Y down):
          0       1       2       3       4       5
 0    0.992   2.043   3.029   4.014   5.021   5.997
 1    0.541   1.088   1.607   2.142   2.705   3.239
 2   -0.417  -0.829  -1.241  -1.665  -2.083  -2.485
 3   -0.978  -1.975  -2.914  -3.913  -4.965  -5.924
 4   -0.648  -1.363  -1.991  -2.606  -3.251  -3.933

 Spline derivative evaluated on X-Y grid:
          0       1       2       3       4       5
 0    1.093   1.013   0.970   1.004   1.001   0.939
 1    0.565   0.531   0.515   0.558   0.559   0.499
 2   -0.429  -0.404  -0.421  -0.423  -0.412  -0.389
 3   -1.060  -0.951  -0.949  -1.048  -1.031  -0.861
 4   -0.779  -0.661  -0.608  -0.628  -0.663  -0.701

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