# NAG Library Routine Document

## 1Purpose

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

## 2Specification

Fortran Interface
 Subroutine e02def ( m, px, py, x, y, mu, c, ff, wrk, iwrk,
 Integer, Intent (In) :: m, px, py Integer, Intent (Inout) :: ifail Integer, Intent (Out) :: iwrk(py-4) Real (Kind=nag_wp), Intent (In) :: x(m), y(m), lamda(px), mu(py), c((px-4)*(py-4)) Real (Kind=nag_wp), Intent (Out) :: ff(m), wrk(py-4)
#include nagmk26.h
 void e02def_ (const Integer *m, const Integer *px, const Integer *py, const double x[], const double y[], const double lamda[], const double mu[], const double c[], double ff[], double wrk[], Integer iwrk[], Integer *ifail)

## 3Description

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).

## 4References

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

## 5Arguments

1:     $\mathbf{m}$ – IntegerInput
On entry: $m$, the number of points at which values of the spline are required.
Constraint: ${\mathbf{m}}\ge 1$.
2:     $\mathbf{px}$ – IntegerInput
3:     $\mathbf{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:     $\mathbf{x}\left({\mathbf{m}}\right)$ – Real (Kind=nag_wp) arrayInput
5:     $\mathbf{y}\left({\mathbf{m}}\right)$ – 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:     $\mathbf{lamda}\left({\mathbf{px}}\right)$ – Real (Kind=nag_wp) arrayInput
7:     $\mathbf{mu}\left({\mathbf{py}}\right)$ – 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:     $\mathbf{c}\left(\left({\mathbf{px}}-4\right)×\left({\mathbf{py}}-4\right)\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:     $\mathbf{ff}\left({\mathbf{m}}\right)$ – 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:   $\mathbf{wrk}\left({\mathbf{py}}-4\right)$ – Real (Kind=nag_wp) arrayWorkspace
11:   $\mathbf{iwrk}\left({\mathbf{py}}-4\right)$ – Integer arrayWorkspace
12:   $\mathbf{ifail}$ – IntegerInput/Output
On entry: ifail must be set to $0$, $-1\text{​ or ​}1$. If you are unfamiliar with this argument you should refer to Section 3.4 in How to Use the NAG Library and its Documentation 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 argument, 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).

## 6Error Indicators and Warnings

If on entry ${\mathbf{ifail}}=0$ or $-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)$.
${\mathbf{ifail}}=-99$
See Section 3.9 in How to Use the NAG Library and its Documentation for further information.
${\mathbf{ifail}}=-399$
Your licence key may have expired or may not have been installed correctly.
See Section 3.8 in How to Use the NAG Library and its Documentation for further information.
${\mathbf{ifail}}=-999$
Dynamic memory allocation failed.
See Section 3.7 in How to Use the NAG Library and its Documentation for further information.

## 7Accuracy

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.

## 8Parallelism and Performance

e02def is not threaded in any implementation.

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

## 10Example

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.

### 10.1Program Text

Program Text (e02defe.f90)

### 10.2Program Data

Program Data (e02defe.d)

### 10.3Program Results

Program Results (e02defe.r)

© The Numerical Algorithms Group Ltd, Oxford, UK. 2017