e02 Chapter Contents
e02 Chapter Introduction
NAG C Library Manual

# NAG Library Function Documentnag_2d_spline_eval (e02dec)

## 1  Purpose

nag_2d_spline_eval (e02dec) calculates values of a bicubic spline from its B-spline representation.

## 2  Specification

 #include #include
 void nag_2d_spline_eval (Integer m, const double x[], const double y[], double ff[], Nag_2dSpline *spline, NagError *fail)

## 3  Description

nag_2d_spline_eval (e02dec) 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}_{\mathit{i}\mathit{j}}$, for $\mathit{i}=1,2,\dots ,\mathbf{spline}\mathbf{\to }\mathbf{nx}-4$ and $\mathit{j}=1,2,\dots ,\mathbf{spline}\mathbf{\to }\mathbf{ny}-4$, in its B-spline representation
 $s x,y = ∑ i,j c ij M i x N j y .$
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 function may be used to calculate values of a bicubic spline given in the form produced by nag_2d_spline_interpolant (e01dac), nag_2d_spline_fit_grid (e02dcc) and nag_2d_spline_fit_scat (e02ddc). 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  Arguments

1:     mIntegerInput
On entry: $m$, the number of points at which values of the spline are required.
Constraint: ${\mathbf{m}}\ge 1$.
2:     x[m]const doubleInput
3:     y[m]const doubleInput
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: x and y must satisfy
$\mathbf{spline}\mathbf{\to }\mathbf{lamda}\left[3\right]\le {\mathbf{x}}\left[\mathit{r}-1\right]\le \mathbf{spline}\mathbf{\to }\mathbf{lamda}\left[\mathbf{spline}\mathbf{\to }\mathbf{nx}-4\right]$
and
$\mathbf{spline}\mathbf{\to }\mathbf{mu}\left[3\right]\le {\mathbf{y}}\left[\mathit{r}-1\right]\le \mathbf{spline}\mathbf{\to }\mathbf{mu}\left[\mathbf{spline}\mathbf{\to }\mathbf{ny}-4\right]$.
The spline representation is not valid outside these intervals, for $\mathit{r}=1,2,\dots ,m$.
4:     ff[m]doubleOutput
On exit: ${\mathbf{ff}}\left[\mathit{r}-1\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$.
5:     splineNag_2dSpline *
Pointer to structure of type Nag_2dSpline with the following members:
nxIntegerInput
On entry: $\mathbf{nx}$ must specify the total number of knots associated with the variables $x$. It is such that $\mathbf{nx}-8$ is the number of interior knots.
Constraint: $\mathbf{nx}\ge 8$.
On entry: a pointer to which memory of size $\mathbf{nx}$ must be allocated. $\mathbf{lamda}$ must contain the complete sets of knots $\left\{\lambda \right\}$ associated with the $x$ variable.
Constraint: the knots must be in non-decreasing order, with $\mathbf{lamda}\left[\mathbf{nx}-4\right]>\mathbf{lamda}\left[3\right]$.
nyIntegerInput
On entry: $\mathbf{ny}$ must specify the total number of knots associated with the variable $y$.
It is such that $\mathbf{ny}-8$ is the number of interior knots.
Constraint: $\mathbf{ny}\ge 8$.
mudoubleInput
On entry: a pointer to which memory of size $\mathbf{ny}$ must be allocated. $\mathbf{mu}$ must contain the complete sets of knots $\left\{\mu \right\}$ associated with the $y$ variable.
Constraint: the knots must be in non-decreasing order, with $\mathbf{mu}\left[\mathbf{ny}-4\right]>\mathbf{mu}\left[3\right]$.
cdoubleInput
On entry: a pointer to which memory of size $\left(\mathbf{nx}-4\right)×\left(\mathbf{ny}-4\right)$ must be allocated. $\mathbf{c}\left[\left(\mathbf{ny}-4\right)×\left(\mathit{i}-1\right)+\mathit{j}-1\right]$ must contain the coefficient ${c}_{\mathit{i}\mathit{j}}$ described in Section 3, for $\mathit{i}=1,2,\dots ,\mathbf{nx}-4$ and $\mathit{j}=1,2,\dots ,\mathbf{ny}-4$.
In normal usage, the call to nag_2d_spline_eval (e02dec) follows a call to nag_2d_spline_interpolant (e01dac), nag_2d_spline_fit_grid (e02dcc) or nag_2d_spline_fit_scat (e02ddc), in which case, members of the structure spline will have been set up correctly for input to nag_2d_spline_eval (e02dec).
6:     failNagError *Input/Output
The NAG error argument (see Section 3.6 in the Essential Introduction).

## 6  Error Indicators and Warnings

NE_ALLOC_FAIL
Dynamic memory allocation failed.
NE_END_KNOTS_CONS
On entry, the end knots must satisfy $〈\mathit{\text{value}}〉$, $〈\mathit{\text{value}}〉=〈\mathit{\text{value}}〉$, $〈\mathit{\text{value}}〉=〈\mathit{\text{value}}〉$.
NE_INT_ARG_LT
On entry, ${\mathbf{m}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{m}}\ge 1$.
On entry, $\mathbf{spline}\mathbf{\to }\mathbf{nx}$ must not be less than 8: $\mathbf{spline}\mathbf{\to }\mathbf{nx}=〈\mathit{\text{value}}〉$.
On entry, $\mathbf{spline}\mathbf{\to }\mathbf{ny}$ must not be less than 8: $\mathbf{spline}\mathbf{\to }\mathbf{ny}=〈\mathit{\text{value}}〉$.
NE_NOT_INCREASING
The sequence $\mathbf{spline}\mathbf{\to }\mathbf{lamda}$ is not increasing: $\mathbf{spline}\mathbf{\to }\mathbf{lamda}\left[〈\mathit{\text{value}}〉\right]=〈\mathit{\text{value}}〉$, $\mathbf{spline}\mathbf{\to }\mathbf{lamda}\left[〈\mathit{\text{value}}〉\right]=〈\mathit{\text{value}}〉$.
The sequence $\mathbf{spline}\mathbf{\to }\mathbf{mu}$ is not increasing: $\mathbf{spline}\mathbf{\to }\mathbf{mu}\left[〈\mathit{\text{value}}〉\right]=〈\mathit{\text{value}}〉$, $\mathbf{spline}\mathbf{\to }\mathbf{mu}\left[〈\mathit{\text{value}}〉\right]=〈\mathit{\text{value}}〉$.
NE_POINT_OUTSIDE_RECT
On entry, point $\left({\mathbf{x}}\left[〈\mathit{\text{value}}〉\right]=〈\mathit{\text{value}}〉,{\mathbf{y}}\left[〈\mathit{\text{value}}〉\right]=〈\mathit{\text{value}}〉\right)$ lies outside the rectangle bounded by $\mathbf{spline}\mathbf{\to }\mathbf{lamda}\left[3\right]=〈\mathit{\text{value}}〉$, $\mathbf{spline}\mathbf{\to }\mathbf{lamda}\left[〈\mathit{\text{value}}〉\right]=〈\mathit{\text{value}}〉$, $\mathbf{spline}\mathbf{\to }\mathbf{mu}\left[3\right]=〈\mathit{\text{value}}〉$, $\mathbf{spline}\mathbf{\to }\mathbf{mu}\left[〈\mathit{\text{value}}〉\right]=〈\mathit{\text{value}}〉$.

## 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{spline}\mathbf{\to }\mathbf{lamda}\left[0\right],\dots ,\mathbf{spline}\mathbf{\to }\mathbf{lamda}\left[\mathbf{spline}\mathbf{\to }\mathbf{nx}-1\right]$ and $\mathbf{spline}\mathbf{\to }\mathbf{mu}\left[0\right],\dots ,\mathbf{spline}\mathbf{\to }\mathbf{mu}\left[\mathbf{spline}\mathbf{\to }\mathbf{ny}-1\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 (e02dece.c)

### 9.2  Program Data

Program Data (e02dece.d)

### 9.3  Program Results

Program Results (e02dece.r)