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(x,y)$s\left(x,y\right)$ on a rectangular grid of points in the x$x$-y$y$ plane, from its augmented knot sets {λ}$\left\{\lambda \right\}$ and {μ}$\left\{\mu \right\}$ and from the coefficients cij${c}_{ij}$, for i = 1,2,,px4$\mathit{i}=1,2,\dots ,{\mathbf{px}}-4$ and j = 1,2,,py4$\mathit{j}=1,2,\dots ,{\mathbf{py}}-4$, in its B-spline representation
 s(x,y) = ∑ cijMi(x)Nj(y). ij
$s(x,y) = ∑ij cij Mi(x) Nj(y) .$
Here Mi(x)${M}_{i}\left(x\right)$ and Nj(y)${N}_{j}\left(y\right)$ denote normalized cubic B-splines, the former defined on the knots λi${\lambda }_{i}$ to λi + 4${\lambda }_{i+4}$ and the latter on the knots μj${\mu }_{j}$ to μj + 4${\mu }_{j+4}$.
The points in the grid are defined by coordinates xq${x}_{q}$, for q = 1,2,,mx$\mathit{q}=1,2,\dots ,{m}_{x}$, along the x$x$ axis, and coordinates yr${y}_{r}$, for r = 1,2,,my$\mathit{r}=1,2,\dots ,{m}_{y}$, along the y$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:     x(mx) – double array
2:     y(my) – double array
mx, the dimension of the array, must satisfy the constraint mx1${\mathbf{mx}}\ge 1$ and my1${\mathbf{my}}\ge 1$.
x and y must contain xq${x}_{\mathit{q}}$, for q = 1,2,,mx$\mathit{q}=1,2,\dots ,{m}_{x}$, and yr${y}_{\mathit{r}}$, for r = 1,2,,my$\mathit{r}=1,2,\dots ,{m}_{y}$, respectively. These are the x$x$ and y$y$ coordinates that define the rectangular grid of points at which values of the spline are required.
Constraint: x${\mathbf{x}}$ and y must satisfy
 lamda(4) ≤ x(q) < x(q + 1) ≤ lamda(px − 3) ,   q = 1,2, … ,mx − 1 $lamda4 ≤ xq < xq+1 ≤ lamdapx-3 , q=1,2,…,mx-1$
and
 mu(4) ≤ y(r) < y(r + 1) ≤ mu(py − 3) ,   r = 1,2, … ,my − 1 . $mu4 ≤ yr < yr+1 ≤ mupy-3 , r= 1,2,…,my- 1 .$
.
The spline representation is not valid outside these intervals.
3:     lamda(px) – double array
4:     mu(py) – double array
px, the dimension of the array, must satisfy the constraint px8${\mathbf{px}}\ge 8$ and py8${\mathbf{py}}\ge 8$.
lamda and mu must contain the complete sets of knots {λ}$\left\{\lambda \right\}$ and {μ}$\left\{\mu \right\}$ associated with the x$x$ and y$y$ variables respectively.
Constraint: the knots in each set must be in nondecreasing order, with lamda(px3) > lamda(4)${\mathbf{lamda}}\left({\mathbf{px}}-3\right)>{\mathbf{lamda}}\left(4\right)$ and mu(py3) > mu(4)${\mathbf{mu}}\left({\mathbf{py}}-3\right)>{\mathbf{mu}}\left(4\right)$.
5:     c((px4) × (py4)$\left({\mathbf{px}}-4\right)×\left({\mathbf{py}}-4\right)$) – double array
c((py4) × (i1) + j)${\mathbf{c}}\left(\left({\mathbf{py}}-4\right)×\left(\mathit{i}-1\right)+\mathit{j}\right)$ must contain the coefficient cij${c}_{\mathit{i}\mathit{j}}$ described in Section [Description], for i = 1,2,,px4$\mathit{i}=1,2,\dots ,{\mathbf{px}}-4$ and j = 1,2,,py4$\mathit{j}=1,2,\dots ,{\mathbf{py}}-4$.

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

Input Parameters Omitted from the MATLAB Interface

wrk lwrk iwrk liwrk

Output Parameters

1:     ff(mx × my${\mathbf{mx}}×{\mathbf{my}}$) – double array
ff(my × (q1) + r)${\mathbf{ff}}\left({\mathbf{my}}×\left(\mathit{q}-1\right)+\mathit{r}\right)$ contains the value of the spline at the point (xq,yr)$\left({x}_{\mathit{q}},{y}_{\mathit{r}}\right)$, for q = 1,2,,mx$\mathit{q}=1,2,\dots ,{m}_{x}$ and r = 1,2,,my$\mathit{r}=1,2,\dots ,{m}_{y}$.
2:     ifail – int64int32nag_int scalar
${\mathrm{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:
ifail = 1${\mathbf{ifail}}=1$
 On entry, mx < 1${\mathbf{mx}}<1$, or my < 1${\mathbf{my}}<1$, or py < 8${\mathbf{py}}<8$, or px < 8${\mathbf{px}}<8$.
ifail = 2${\mathbf{ifail}}=2$
 On entry, lwrk is too small, or liwrk is too small.
ifail = 3${\mathbf{ifail}}=3$
On entry, the knots in array lamda, or those in array mu, are not in nondecreasing order, or lamda(px3)lamda(4)${\mathbf{lamda}}\left({\mathbf{px}}-3\right)\le {\mathbf{lamda}}\left(4\right)$, or mu(py3)mu(4)${\mathbf{mu}}\left({\mathbf{py}}-3\right)\le {\mathbf{mu}}\left(4\right)$.
ifail = 4${\mathbf{ifail}}=4$
On entry, the restriction lamda(4)x(1) < < x(mx)lamda(px3)${\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 mu(4)y(1) < < y(my)mu(py3)${\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.

Accuracy

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

Example

```function nag_fit_2dspline_evalm_example
x = [1;
1.1;
1.3;
1.4;
1.5;
1.7;
2];
y = [0;
0.2;
0.4;
0.6;
0.8;
1];
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.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];
[ff, ifail] = nag_fit_2dspline_evalm(x, y, lamda, mu, c)
```
```

ff =

1.0000
1.2000
1.4000
1.6000
1.8000
2.0000
1.2100
1.4100
1.6100
1.8100
2.0100
2.2100
1.6900
1.8900
2.0900
2.2900
2.4900
2.6900
1.9600
2.1600
2.3600
2.5600
2.7600
2.9600
2.2500
2.4500
2.6500
2.8500
3.0500
3.2500
2.8900
3.0900
3.2900
3.4900
3.6900
3.8900
4.0000
4.2000
4.4000
4.6000
4.8000
5.0000

ifail =

0

```
```function e02df_example
x = [1;
1.1;
1.3;
1.4;
1.5;
1.7;
2];
y = [0;
0.2;
0.4;
0.6;
0.8;
1];
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.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];
[ff, ifail] = e02df(x, y, lamda, mu, c)
```
```

ff =

1.0000
1.2000
1.4000
1.6000
1.8000
2.0000
1.2100
1.4100
1.6100
1.8100
2.0100
2.2100
1.6900
1.8900
2.0900
2.2900
2.4900
2.6900
1.9600
2.1600
2.3600
2.5600
2.7600
2.9600
2.2500
2.4500
2.6500
2.8500
3.0500
3.2500
2.8900
3.0900
3.2900
3.4900
3.6900
3.8900
4.0000
4.2000
4.4000
4.6000
4.8000
5.0000

ifail =

0

```