e02 Chapter Contents
e02 Chapter Introduction
NAG C Library Manual

# NAG Library Function Documentnag_2d_spline_eval_rect (e02dfc)

## 1  Purpose

nag_2d_spline_eval_rect (e02dfc) calculates values of a bicubic spline from its B-spline representation. The spline is evaluated at all points on a rectangular grid.

## 2  Specification

 #include #include
 void nag_2d_spline_eval_rect (Integer mx, Integer my, const double x[], const double y[], double ff[], Nag_2dSpline *spline, NagError *fail)

## 3  Description

nag_2d_spline_eval_rect (e02dfc) calculates values of the bicubic spline $s\left(x,y\right)$ on a rectangular grid of points in the $x$-$y$ plane, 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}$.
The points in the grid are defined by coordinates ${x}_{\mathit{q}}$, for $\mathit{q}=1,2,\dots ,{m}_{x}$, along the $x$ axis, and coordinates ${y}_{\mathit{r}}$, for $\mathit{r}=1,2,\dots ,{m}_{y}$ along the $y$ axis.
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:     mxIntegerInput
2:     myIntegerInput
On entry: mx and my must specify ${m}_{x}$ and ${m}_{y}$ respectively, the number of points along the $x$ and $y$ axes that define the rectangular grid.
Constraint: ${\mathbf{mx}}\ge 1$ and ${\mathbf{my}}\ge 1$.
3:     x[mx]const doubleInput
4:     y[my]const doubleInput
On entry: x and y must contain ${x}_{\mathit{q}}$, for $\mathit{q}=1,2,\dots ,{m}_{x}$, and ${y}_{\mathit{r}}$, for $\mathit{r}=1,2,\dots ,{m}_{y}$, respectively. These are the $x$ and $y$ coordinates that define the rectangular grid of points at which values of the spline are required.
Constraint: x and y must satisfy $\mathbf{spline}\mathbf{\to }\mathbf{lamda}\left[3\right]\le {\mathbf{x}}\left[\mathit{q}-1\right]<{\mathbf{x}}\left[\mathit{q}\right]\le \mathbf{spline}\mathbf{\to }\mathbf{lamda}\left[\mathbf{spline}\mathbf{\to }\mathbf{nx}-4\right]$, for $\mathit{q}=1,2,\dots ,{m}_{x}-1$, and $\mathbf{spline}\mathbf{\to }\mathbf{mu}\left[3\right]\le {\mathbf{y}}\left[\mathit{r}-1\right]<{\mathbf{y}}\left[\mathit{r}\right]\le \mathbf{spline}\mathbf{\to }\mathbf{mu}\left[\mathbf{spline}\mathbf{\to }\mathbf{ny}-4\right]$, for $\mathit{r}=1,2,\dots ,{m}_{y}-1$.
The spline representation is not valid outside these intervals.
5:     ff[${\mathbf{mx}}×{\mathbf{my}}$]doubleOutput
On exit: ${\mathbf{ff}}\left[{\mathbf{my}}×\left(\mathit{q}-1\right)+\mathit{r}-1\right]$ contains the value of the spline at the point $\left({x}_{\mathit{q}},{y}_{\mathit{r}}\right)$, for $\mathit{q}=1,2,\dots ,{m}_{x}$ and $\mathit{r}=1,2,\dots ,{m}_{y}$.
6:     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 variable $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(i-1\right)+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_rect (e02dfc) 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_rect (e02dfc).
7:     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{mx}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{mx}}\ge 1$.
On entry, ${\mathbf{my}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{my}}\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_KNOTS_COORD_CONS
On entry, the end knots and coordinates must satisfy $\mathbf{spline}\mathbf{\to }\mathbf{lamda}\left[3\right]\le {\mathbf{x}}\left[0\right]$ and ${\mathbf{x}}\left[{\mathbf{mx}}-1\right]\le \mathbf{spline}\mathbf{\to }\mathbf{lamda}\left[\mathbf{spline}\mathbf{\to }\mathbf{nx}-4\right]$. $\mathbf{spline}\mathbf{\to }\mathbf{lamda}\left[3\right]=〈\mathit{\text{value}}〉$, ${\mathbf{x}}\left[0\right]=〈\mathit{\text{value}}〉$, ${\mathbf{x}}\left[〈\mathit{\text{value}}〉\right]=〈\mathit{\text{value}}〉$, $\mathbf{spline}\mathbf{\to }\mathbf{lamda}\left[〈\mathit{\text{value}}〉\right]=〈\mathit{\text{value}}〉$.
On entry, the end knots and coordinates must satisfy $\mathbf{spline}\mathbf{\to }\mathbf{mu}\left[3\right]\le {\mathbf{y}}\left[0\right]$ and ${\mathbf{y}}\left[{\mathbf{my}}-1\right]\le \mathbf{spline}\mathbf{\to }\mathbf{mu}\left[\mathbf{spline}\mathbf{\to }\mathbf{ny}-4\right]$. $\mathbf{spline}\mathbf{\to }\mathbf{mu}\left[3\right]=〈\mathit{\text{value}}〉$, ${\mathbf{y}}\left[0\right]=〈\mathit{\text{value}}〉$, ${\mathbf{y}}\left[〈\mathit{\text{value}}〉\right]=〈\mathit{\text{value}}〉$, $\mathbf{spline}\mathbf{\to }\mathbf{mu}\left[〈\mathit{\text{value}}〉\right]=〈\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_NOT_STRICTLY_INCREASING
The sequence x is not strictly increasing: ${\mathbf{x}}\left[〈\mathit{\text{value}}〉\right]=〈\mathit{\text{value}}〉$, ${\mathbf{x}}\left[〈\mathit{\text{value}}〉\right]=〈\mathit{\text{value}}〉$.
The sequence y is not strictly increasing: ${\mathbf{y}}\left[〈\mathit{\text{value}}〉\right]=〈\mathit{\text{value}}〉$, ${\mathbf{y}}\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 ${m}_{x}{m}_{y}+4\left({m}_{x}+{m}_{y}\right)$.

## 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]\text{​ 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 values for ${m}_{x}$ and the $x$ coordinates ${x}_{\mathit{q}}$, for $\mathit{q}=1,2,\dots ,{m}_{x}$, and values for ${m}_{y}$ and the $y$ coordinates ${y}_{\mathit{r}}$, for $\mathit{r}=1,2,\dots ,{m}_{y}$, defining the grid of points on which the spline is to be evaluated.

### 9.1  Program Text

Program Text (e02dfce.c)

### 9.2  Program Data

Program Data (e02dfce.d)

### 9.3  Program Results

Program Results (e02dfce.r)