E02 Chapter Contents
E02 Chapter Introduction
NAG Library Manual

# NAG Library Routine DocumentE02DEF

Note:  before using this routine, please read the Users' Note for your implementation to check the interpretation of bold italicised terms and other implementation-dependent details.

## 1  Purpose

E02DEF calculates values of a bicubic spline from its B-spline representation.

## 2  Specification

 SUBROUTINE E02DEF ( M, PX, PY, X, Y, LAMDA, MU, C, FF, WRK, IWRK, IFAIL)
 INTEGER M, PX, PY, IWRK(PY-4), IFAIL REAL (KIND=nag_wp) X(M), Y(M), LAMDA(PX), MU(PY), C((PX-4)*(PY-4)), FF(M), WRK(PY-4)

## 3  Description

E02DEF calculates values of the bicubic spline $s\left(x,y\right)$ at prescribed points $\left({x}_{\mathit{r}},{y}_{\mathit{r}}\right)$, for $\mathit{r}=1,2,\dots ,m$, 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=∑ijcijMixNjy.$
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}$.
This routine may be used to calculate values of a bicubic spline given in the form produced by E01DAF, E02DAF, E02DCF and E02DDF. It is derived from the routine B2VRE in Anthony et al. (1982).

## 4  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

## 5  Parameters

1:     M – INTEGERInput
On entry: $m$, the number of points at which values of the spline are required.
Constraint: ${\mathbf{M}}\ge 1$.
2:     PX – INTEGERInput
3:     PY – INTEGERInput
On entry: 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$.
4:     X(M) – REAL (KIND=nag_wp) arrayInput
5:     Y(M) – REAL (KIND=nag_wp) arrayInput
On entry: X and Y must contain ${x}_{\mathit{r}}$ and ${y}_{\mathit{r}}$, for $\mathit{r}=1,2,\dots ,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: ${\mathbf{X}}$ and ${\mathbf{Y}}$ must satisfy
 $LAMDA4≤Xr≤LAMDAPX-3$
and
 $MU4≤Yr≤MUPY- 3, r= 1,2,…,m.$
.
The spline representation is not valid outside these intervals.
6:     LAMDA(PX) – REAL (KIND=nag_wp) arrayInput
7:     MU(PY) – REAL (KIND=nag_wp) arrayInput
On entry: 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)$.
8:     C($\left({\mathbf{PX}}-4\right)×\left({\mathbf{PY}}-4\right)$) – REAL (KIND=nag_wp) arrayInput
On entry: ${\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 Section 3, for $\mathit{i}=1,2,\dots ,{\mathbf{PX}}-4$ and $\mathit{j}=1,2,\dots ,{\mathbf{PY}}-4$.
9:     FF(M) – REAL (KIND=nag_wp) arrayOutput
On exit: ${\mathbf{FF}}\left(\mathit{r}\right)$ contains the value of the spline at the point $\left({x}_{\mathit{r}},{y}_{\mathit{r}}\right)$, for $\mathit{r}=1,2,\dots ,m$.
10:   WRK(${\mathbf{PY}}-4$) – REAL (KIND=nag_wp) arrayWorkspace
11:   IWRK(${\mathbf{PY}}-4$) – INTEGER arrayWorkspace
12:   IFAIL – INTEGERInput/Output
On entry: IFAIL must be set to $0$, $-1\text{​ or ​}1$. If you are unfamiliar with this parameter you should refer to Section 3.3 in the Essential Introduction for details.
For environments where it might be inappropriate to halt program execution when an error is detected, the value $-1\text{​ or ​}1$ is recommended. If the output of error messages is undesirable, then the value $1$ is recommended. Otherwise, if you are not familiar with this parameter, the recommended value is $0$. When the value $-\mathbf{1}\text{​ or ​}\mathbf{1}$ is used it is essential to test the value of IFAIL on exit.
On exit: ${\mathbf{IFAIL}}={\mathbf{0}}$ unless the routine detects an error or a warning has been flagged (see Section 6).

## 6  Error Indicators and Warnings

If on entry ${\mathbf{IFAIL}}={\mathbf{0}}$ or $-{\mathbf{1}}$, explanatory error messages are output on the current error message unit (as defined by X04AAF).
Errors or warnings detected by the routine:
${\mathbf{IFAIL}}=1$
 On entry, ${\mathbf{M}}<1$, or ${\mathbf{PY}}<8$, or ${\mathbf{PX}}<8$.
${\mathbf{IFAIL}}=2$
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}}=3$
On entry, at least one of the prescribed points $\left({x}_{r},{y}_{r}\right)$ lies outside the rectangle defined by ${\mathbf{LAMDA}}\left(4\right)$, ${\mathbf{LAMDA}}\left({\mathbf{PX}}-3\right)$ and ${\mathbf{MU}}\left(4\right)$, ${\mathbf{MU}}\left({\mathbf{PY}}-3\right)$.

## 7  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 the number of points, $m$, at which the evaluation is required.

## 9  Example

This program 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 a value for $m$ and the coordinates $\left({x}_{\mathit{r}},{y}_{\mathit{r}}\right)$, for $\mathit{r}=1,2,\dots ,m$, at which the spline is to be evaluated.

### 9.1  Program Text

Program Text (e02defe.f90)

### 9.2  Program Data

Program Data (e02defe.d)

### 9.3  Program Results

Program Results (e02defe.r)