# NAG Library Routine Document

## 1Purpose

e02dhf computes the partial derivative (of order ${\nu }_{x}$, ${\nu }_{y}$), of a bicubic spline approximation to a set of data values, from its B-spline representation, at points on a rectangular grid in the $x$-$y$ plane. This routine may be used to calculate derivatives of a bicubic spline given in the form produced by e01daf, e02daf, e02dcf and e02ddf.

## 2Specification

Fortran Interface
 Subroutine e02dhf ( mx, my, px, py, x, y, mu, c, nux, nuy, z,
 Integer, Intent (In) :: mx, my, px, py, nux, nuy Integer, Intent (Inout) :: ifail Real (Kind=nag_wp), Intent (In) :: x(mx), y(my), lamda(px), mu(py), c((px-4)*(py-4)) Real (Kind=nag_wp), Intent (Out) :: z(mx*my)
#include <nagmk26.h>
 void e02dhf_ (const Integer *mx, const Integer *my, const Integer *px, const Integer *py, const double x[], const double y[], const double lamda[], const double mu[], const double c[], const Integer *nux, const Integer *nuy, double z[], Integer *ifail)

## 3Description

e02dhf determines the partial derivative $\frac{{\partial }^{{\nu }_{x}+{\nu }_{y}}}{\partial {x}^{{\nu }_{x}}\partial {y}^{{\nu }_{y}}}$ of a smooth bicubic spline approximation $s\left(x,y\right)$ at the set of data points $\left({x}_{q},{y}_{r}\right)$.
The spline is given in the B-spline representation
 $sx,y = ∑ i=1 nx-4 ∑ j=1 ny-4 cij Mix Njy ,$ (1)
where ${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}$, with ${n}_{x}$ and ${n}_{y}$ the total numbers of knots of the computed spline with respect to the $x$ and $y$ variables respectively. For further details, see Hayes and Halliday (1974) for bicubic splines and de Boor (1972) for normalized B-splines. This routine is suitable for B-spline representations returned by e01daf, e02daf, e02dcf and e02ddf.
The partial derivatives can be up to order $2$ in each direction; thus the highest mixed derivative available is $\frac{{\partial }^{4}}{\partial {x}^{2}\partial {y}^{2}}$.
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.

## 4References

de Boor C (1972) On calculating with B-splines J. Approx. Theory 6 50–62
Dierckx P (1981) An improved algorithm for curve fitting with spline functions Report TW54 Department of Computer Science, Katholieke Univerciteit Leuven
Dierckx P (1982) A fast algorithm for smoothing data on a rectangular grid while using spline functions SIAM J. Numer. Anal. 19 1286–1304
Hayes J G and Halliday J (1974) The least squares fitting of cubic spline surfaces to general data sets J. Inst. Math. Appl. 14 89–103
Reinsch C H (1967) Smoothing by spline functions Numer. Math. 10 177–183

## 5Arguments

1:     $\mathbf{mx}$ – IntegerInput
On entry: ${m}_{x}$, the number of grid points along the $x$ axis.
Constraint: ${\mathbf{mx}}\ge 1$.
2:     $\mathbf{my}$ – IntegerInput
On entry: ${m}_{y}$, the number of grid points along the $y$ axis.
Constraint: ${\mathbf{my}}\ge 1$.
3:     $\mathbf{px}$ – IntegerInput
On entry: the total number of knots in the $x$-direction of the bicubic spline approximation, e.g., the value nx as returned by e02dcf.
4:     $\mathbf{py}$ – IntegerInput
On entry: the total number of knots in the $y$-direction of the bicubic spline approximation, e.g., the value ny as returned by e02dcf.
5:     $\mathbf{x}\left({\mathbf{mx}}\right)$ – Real (Kind=nag_wp) arrayInput
On entry: ${\mathbf{x}}\left(q\right)$ must be set to ${x}_{\mathit{q}}$, the $x$ coordinate of the $\mathit{q}$th grid point along the $x$ axis, for $\mathit{q}=1,2,\dots ,{m}_{x}$, on which values of the partial derivative are sought.
Constraint: ${x}_{1}<{x}_{2}<\cdots <{x}_{{m}_{x}}$.
6:     $\mathbf{y}\left({\mathbf{my}}\right)$ – Real (Kind=nag_wp) arrayInput
On entry: ${\mathbf{y}}\left(\mathit{r}\right)$ must be set to ${y}_{\mathit{r}}$, the $y$ coordinate of the $\mathit{r}$th grid point along the $y$ axis, for $\mathit{r}=1,2,\dots ,{m}_{y}$ on which values of the partial derivative are sought.
Constraint: ${y}_{1}<{y}_{2}<\cdots <{y}_{{m}_{y}}$.
7:     $\mathbf{lamda}\left({\mathbf{px}}\right)$ – Real (Kind=nag_wp) arrayInput
On entry: contains the position of the knots in the $x$-direction of the bicubic spline approximation to be differentiated, e.g., lamda as returned by e02dcf.
8:     $\mathbf{mu}\left({\mathbf{py}}\right)$ – Real (Kind=nag_wp) arrayInput
On entry: contains the position of the knots in the $y$-direction of the bicubic spline approximation to be differentiated, e.g., mu as returned by e02dcf.
9:     $\mathbf{c}\left(\left({\mathbf{px}}-4\right)×\left({\mathbf{py}}-4\right)\right)$ – Real (Kind=nag_wp) arrayInput
On entry: the coefficients of the bicubic spline approximation to be differentiated, e.g., c as returned by e02dcf.
10:   $\mathbf{nux}$ – IntegerInput
On entry: specifies the order, ${\nu }_{x}$ of the partial derivative in the $x$-direction.
Constraint: $0\le {\mathbf{nux}}\le 2$.
11:   $\mathbf{nuy}$ – IntegerInput
On entry: specifies the order, ${\nu }_{y}$ of the partial derivative in the $y$-direction.
Constraint: $0\le {\mathbf{nuy}}\le 2$.
12:   $\mathbf{z}\left({\mathbf{mx}}×{\mathbf{my}}\right)$ – Real (Kind=nag_wp) arrayOutput
On exit: ${\mathbf{z}}\left({m}_{y}×\left(\mathit{q}-1\right)+\mathit{r}\right)$ contains the derivative $\frac{{\partial }^{{\nu }_{x}+{\nu }_{y}}}{{\partial x}^{{\nu }_{x}}{\partial y}^{{\nu }_{y}}}s\left({x}_{q},{y}_{r}\right)$, for $\mathit{q}=1,2,\dots ,{m}_{x}$ and $\mathit{r}=1,2,\dots ,{m}_{y}$.
13:   $\mathbf{ifail}$ – IntegerInput/Output
On entry: ifail must be set to $0$, . 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  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  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{nux}}=〈\mathit{\text{value}}〉$.
Constraint: $0\le {\mathbf{nux}}\le 2$.
${\mathbf{ifail}}=2$
On entry, ${\mathbf{nuy}}=〈\mathit{\text{value}}〉$.
Constraint: $0\le {\mathbf{nuy}}\le 2$.
${\mathbf{ifail}}=3$
On entry, ${\mathbf{mx}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{mx}}\ge 1$.
${\mathbf{ifail}}=4$
On entry, ${\mathbf{my}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{my}}\ge 1$.
${\mathbf{ifail}}=5$
On entry, for $i=〈\mathit{\text{value}}〉$, ${\mathbf{x}}\left(i-1\right)=〈\mathit{\text{value}}〉$ and ${\mathbf{x}}\left(i\right)=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{x}}\left(\mathit{i}-1\right)\le {\mathbf{x}}\left(\mathit{i}\right)$, for $\mathit{i}=2,3,\dots ,{\mathbf{mx}}$.
${\mathbf{ifail}}=6$
On entry, for $i=〈\mathit{\text{value}}〉$, ${\mathbf{y}}\left(i-1\right)=〈\mathit{\text{value}}〉$ and ${\mathbf{y}}\left(i\right)=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{y}}\left(\mathit{i}-1\right)\le {\mathbf{y}}\left(\mathit{i}\right)$, for $\mathit{i}=2,3,\dots ,{\mathbf{my}}$.
${\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

On successful exit, the partial derivatives on the given mesh are accurate to machine precision with respect to the supplied bicubic spline. Please refer to Section 7 in e01daf, e02daf, e02dcf and e02ddf of the routine document for the respective routine which calculated the spline approximant for details on the accuracy of that approximation.

## 8Parallelism and Performance

e02dhf makes calls to BLAS and/or LAPACK routines, which may be threaded within the vendor library used by this implementation. Consult the documentation for the vendor library for further information.
Please consult the X06 Chapter Introduction for information on how to control and interrogate the OpenMP environment used within this routine. Please also consult the Users' Note for your implementation for any additional implementation-specific information.

None.

## 10Example

This example reads in values of ${m}_{x}$, ${m}_{y}$, ${x}_{\mathit{q}}$, for $\mathit{q}=1,2,\dots ,{m}_{x}$, and ${y}_{\mathit{r}}$, for $\mathit{r}=1,2,\dots ,{m}_{y}$, followed by values of the ordinates ${f}_{q,r}$ defined at the grid points $\left({x}_{q},{y}_{r}\right)$. It then calls e02dcf to compute a bicubic spline approximation for one specified value of $S$. Finally it evaluates the spline and its first $x$ derivative at a small sample of points on a rectangular grid by calling e02dhf.

### 10.1Program Text

Program Text (e02dhfe.f90)

### 10.2Program Data

Program Data (e02dhfe.d)

### 10.3Program Results

Program Results (e02dhfe.r)