# NAG FL Interfacee02def (dim2_​spline_​evalv)

## 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 <nag.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)
The routine may be called by the names e02def or nagf_fit_dim2_spline_evalv.

## 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}$Integer Input
On entry: $m$, the number of points at which values of the spline are required.
Constraint: ${\mathbf{m}}\ge 1$.
2: $\mathbf{px}$Integer Input
3: $\mathbf{py}$Integer Input
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) array Input
5: $\mathbf{y}\left({\mathbf{m}}\right)$Real (Kind=nag_wp) array Input
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) array Input
7: $\mathbf{mu}\left({\mathbf{py}}\right)$Real (Kind=nag_wp) array Input
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) array Input
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) array Output
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) array Workspace
11: $\mathbf{iwrk}\left({\mathbf{py}}-4\right)$Integer array Workspace
12: $\mathbf{ifail}$Integer Input/Output
On entry: ifail must be set to $0$, $-1$ or $1$ to set behaviour on detection of an error; these values have no effect when no error is detected.
A value of $0$ causes the printing of an error message and program execution will be halted; otherwise program execution continues. A value of $-1$ means that an error message is printed while a value of $1$ means that it is not.
If halting is not appropriate, the value $-1$ or $1$ is recommended. If message printing is undesirable, then the value $1$ is recommended. Otherwise, the value $0$ is recommended. When the value $-\mathbf{1}$ 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}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{m}}\ge 1$.
On entry, ${\mathbf{px}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{px}}\ge 8$.
On entry, ${\mathbf{py}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{py}}\ge 8$.
${\mathbf{ifail}}=2$
On entry, the knots in lamda are not in nondecreasing order.
On entry, the knots in mu are not in nondecreasing order.
${\mathbf{ifail}}=3$
On entry, point $\left({\mathbf{x}}\left(\mathit{K}\right),{\mathbf{y}}\left(\mathit{K}\right)\right)$ lies outside the rectangle bounded by ${\mathbf{lamda}}\left(4\right)$, ${\mathbf{lamda}}\left({\mathbf{px}}-3\right)$, ${\mathbf{mu}}\left(4\right)$, ${\mathbf{mu}}\left({\mathbf{py}}-3\right)$: $\mathit{K}=〈\mathit{\text{value}}〉$, ${\mathbf{x}}\left(\mathit{K}\right)=〈\mathit{\text{value}}〉$ and ${\mathbf{y}}\left(\mathit{K}\right)=〈\mathit{\text{value}}〉$.
${\mathbf{ifail}}=-99$
See Section 7 in the Introduction to the NAG Library FL Interface for further information.
${\mathbf{ifail}}=-399$
Your licence key may have expired or may not have been installed correctly.
See Section 8 in the Introduction to the NAG Library FL Interface for further information.
${\mathbf{ifail}}=-999$
Dynamic memory allocation failed.
See Section 9 in the Introduction to the NAG Library FL Interface 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)