Integer type:  int32  int64  nag_int  show int32  show int32  show int64  show int64  show nag_int  show nag_int

Chapter Contents
Chapter Introduction
NAG Toolbox

# NAG Toolbox: nag_fit_2dspline_evalm (e02df)

## Purpose

nag_fit_2dspline_evalm (e02df) calculates values of a bicubic spline from its B-spline representation. The spline is evaluated at all points on a rectangular grid.

## Syntax

[ff, ifail] = e02df(x, y, lamda, mu, c, 'mx', mx, 'my', my, 'px', px, 'py', py)
[ff, ifail] = nag_fit_2dspline_evalm(x, y, lamda, mu, c, 'mx', mx, 'my', my, 'px', px, 'py', py)

## Description

nag_fit_2dspline_evalm (e02df) calculates values of the bicubic spline $s\left(x,y\right)$ on a rectangular grid of points in the $x$-$y$ plane, from its augmented knot sets $\left\{\lambda \right\}$ and $\left\{\mu \right\}$ and from the coefficients ${c}_{ij}$, for $\mathit{i}=1,2,\dots ,{\mathbf{px}}-4$ and $\mathit{j}=1,2,\dots ,{\mathbf{py}}-4$, in its B-spline representation
 $sx,y = ∑ij cij Mix Njy .$
Here ${M}_{i}\left(x\right)$ and ${N}_{j}\left(y\right)$ denote normalized cubic B-splines, the former defined on the knots ${\lambda }_{i}$ to ${\lambda }_{i+4}$ and the latter on the knots ${\mu }_{j}$ to ${\mu }_{j+4}$.
The points in the grid are defined by coordinates ${x}_{q}$, for $\mathit{q}=1,2,\dots ,{m}_{x}$, along the $x$ axis, and coordinates ${y}_{r}$, for $\mathit{r}=1,2,\dots ,{m}_{y}$, along the $y$ axis.
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).

## References

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

## Parameters

### Compulsory Input Parameters

1:     $\mathrm{x}\left({\mathbf{mx}}\right)$ – double array
2:     $\mathrm{y}\left({\mathbf{my}}\right)$ – double array
x and y must contain ${x}_{\mathit{q}}$, for $\mathit{q}=1,2,\dots ,{m}_{x}$, and ${y}_{\mathit{r}}$, for $\mathit{r}=1,2,\dots ,{m}_{y}$, respectively. These are the $x$ and $y$ coordinates that define the rectangular grid of points at which values of the spline are required.
Constraint: ${\mathbf{x}}$ and y must satisfy
 $lamda4 ≤ xq < xq+1 ≤ lamdapx-3 , q=1,2,…,mx-1$
and
 $mu4 ≤ yr < yr+1 ≤ mupy-3 , r= 1,2,…,my- 1 .$
.
The spline representation is not valid outside these intervals.
3:     $\mathrm{lamda}\left({\mathbf{px}}\right)$ – double array
4:     $\mathrm{mu}\left({\mathbf{py}}\right)$ – double array
lamda and mu must contain the complete sets of knots $\left\{\lambda \right\}$ and $\left\{\mu \right\}$ associated with the $x$ and $y$ variables respectively.
Constraint: the knots in each set must be in nondecreasing order, with ${\mathbf{lamda}}\left({\mathbf{px}}-3\right)>{\mathbf{lamda}}\left(4\right)$ and ${\mathbf{mu}}\left({\mathbf{py}}-3\right)>{\mathbf{mu}}\left(4\right)$.
5:     $\mathrm{c}\left(\left({\mathbf{px}}-4\right)×\left({\mathbf{py}}-4\right)\right)$ – double array
${\mathbf{c}}\left(\left({\mathbf{py}}-4\right)×\left(\mathit{i}-1\right)+\mathit{j}\right)$ must contain the coefficient ${c}_{\mathit{i}\mathit{j}}$ described in Description, for $\mathit{i}=1,2,\dots ,{\mathbf{px}}-4$ and $\mathit{j}=1,2,\dots ,{\mathbf{py}}-4$.

### Optional Input Parameters

1:     $\mathrm{mx}$int64int32nag_int scalar
2:     $\mathrm{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 ${m}_{x}$ and ${m}_{y}$ respectively, the number of points along the $x$ and $y$ axis that define the rectangular grid.
Constraint: ${\mathbf{mx}}\ge 1$ and ${\mathbf{my}}\ge 1$.
3:     $\mathrm{px}$int64int32nag_int scalar
4:     $\mathrm{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 ${\mathbf{px}}-8$ and ${\mathbf{py}}-8$ are the corresponding numbers of interior knots.
Constraint: ${\mathbf{px}}\ge 8$ and ${\mathbf{py}}\ge 8$.

### Output Parameters

1:     $\mathrm{ff}\left({\mathbf{mx}}×{\mathbf{my}}\right)$ – double array
${\mathbf{ff}}\left({\mathbf{my}}×\left(\mathit{q}-1\right)+\mathit{r}\right)$ contains the value of the spline at the point $\left({x}_{\mathit{q}},{y}_{\mathit{r}}\right)$, for $\mathit{q}=1,2,\dots ,{m}_{x}$ and $\mathit{r}=1,2,\dots ,{m}_{y}$.
2:     $\mathrm{ifail}$int64int32nag_int scalar
${\mathbf{ifail}}={\mathbf{0}}$ unless the function detects an error (see Error Indicators and Warnings).

## Error Indicators and Warnings

Errors or warnings detected by the function:
${\mathbf{ifail}}=1$
 On entry, ${\mathbf{mx}}<1$, or ${\mathbf{my}}<1$, or ${\mathbf{py}}<8$, or ${\mathbf{px}}<8$.
${\mathbf{ifail}}=2$
 On entry, lwrk is too small, or liwrk is too small.
${\mathbf{ifail}}=3$
On entry, the knots in array lamda, or those in array mu, are not in nondecreasing order, or ${\mathbf{lamda}}\left({\mathbf{px}}-3\right)\le {\mathbf{lamda}}\left(4\right)$, or ${\mathbf{mu}}\left({\mathbf{py}}-3\right)\le {\mathbf{mu}}\left(4\right)$.
${\mathbf{ifail}}=4$
On entry, the restriction ${\mathbf{lamda}}\left(4\right)\le {\mathbf{x}}\left(1\right)<\cdots <{\mathbf{x}}\left({\mathbf{mx}}\right)\le {\mathbf{lamda}}\left({\mathbf{px}}-3\right)$, or the restriction ${\mathbf{mu}}\left(4\right)\le {\mathbf{y}}\left(1\right)<\cdots <{\mathbf{y}}\left({\mathbf{my}}\right)\le {\mathbf{mu}}\left({\mathbf{py}}-3\right)$, is violated.
${\mathbf{ifail}}=-99$
${\mathbf{ifail}}=-399$
Your licence key may have expired or may not have been installed correctly.
${\mathbf{ifail}}=-999$
Dynamic memory allocation failed.

## Accuracy

The method used to evaluate the B-splines is numerically stable, in the sense that each computed value of $s\left({x}_{r},{y}_{r}\right)$ 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.

Computation time is approximately proportional to ${m}_{x}{m}_{y}+4\left({m}_{x}+{m}_{y}\right)$.

## Example

This example reads in knot sets ${\mathbf{lamda}}\left(1\right),\dots ,{\mathbf{lamda}}\left({\mathbf{px}}\right)$ and ${\mathbf{mu}}\left(1\right),\dots ,{\mathbf{mu}}\left({\mathbf{py}}\right)$, and a set of bicubic spline coefficients ${c}_{ij}$. Following these are values for ${m}_{x}$ and the $x$ coordinates ${x}_{q}$, for $\mathit{q}=1,2,\dots ,{m}_{x}$, and values for ${m}_{y}$ and the $y$ coordinates ${y}_{r}$, for $\mathit{r}=1,2,\dots ,{m}_{y}$, defining the grid of points on which the spline is to be evaluated.
```function e02df_example

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

% knots
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];
% Coefficients
c     = [1       1.1333  1.3667  1.7   1.9     2  ...
1.2     1.3333  1.5667  1.9     2.1   2.2 ...
1.5833  1.7167  1.95    2.2833  2.4833  2.5833 ...
2.1433  2.2767  2.51    2.8433  3.0433  3.1433 ...
2.8667  3       3.2333  3.5667  3.7667  3.8667 ...
3.4667  3.6     3.8333  4.1667  4.3667  4.4667 ...
4       4.1333  4.3667  4.7     4.9     5];

%Evaluation points
x = [1.0  1.1  1.3  1.4  1.5  1.7  2.0];
y = [0 : 0.2 : 1];

% Spline evaluation
[ff, ifail] = e02df( ...
x, y, lamda, mu, c);

fprintf(' Spline evaluated on x-y grid (x across, y down):\n');
ff = reshape(ff,[6,7]);
fprintf('%5s%9.1f%9.1f%9.1f%9.1f%9.1f%9.1f%9.1f\n',' ',x);
for i = 1:6
fprintf('%5.1f%9.3f%9.3f%9.3f%9.3f%9.3f%9.3f%9.3f\n',y(i),ff(i,:));
end

```
```e02df example results

Spline evaluated on x-y grid (x across, y down):
1.0      1.1      1.3      1.4      1.5      1.7      2.0
0.0    1.000    1.210    1.690    1.960    2.250    2.890    4.000
0.2    1.200    1.410    1.890    2.160    2.450    3.090    4.200
0.4    1.400    1.610    2.090    2.360    2.650    3.290    4.400
0.6    1.600    1.810    2.290    2.560    2.850    3.490    4.600
0.8    1.800    2.010    2.490    2.760    3.050    3.690    4.800
1.0    2.000    2.210    2.690    2.960    3.250    3.890    5.000
```