The routine may be called by the names e01daf or nagf_interp_dim2_spline_grid.
3Description
e01daf determines a bicubic spline interpolant to the set of data points
$({x}_{\mathit{q}},{y}_{\mathit{r}},{f}_{\mathit{q},\mathit{r}})$, for $\mathit{q}=1,2,\dots ,{m}_{x}$ and $\mathit{r}=1,2,\dots ,{m}_{y}$. The spline is given in the B-spline representation
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}$, and the ${c}_{ij}$ are the spline coefficients. These knots, as well as the coefficients, are determined by the routine, which is derived from the routine B2IRE in Anthony et al. (1982). The method used is described in Section 9.2.
Values and derivatives of the computed spline can subsequently be computed by calling e02def,e02dffore02dhf as described in Section 9.3.
4References
Anthony G T, Cox M G and Hayes J G (1982) DASL – Data Approximation Subroutine Library National Physical Laboratory
Cox M G (1975) An algorithm for spline interpolation J. Inst. Math. Appl.15 95–108
de Boor C (1972) On calculating with B-splines J. Approx. Theory6 50–62
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
5Arguments
1: $\mathbf{mx}$ – IntegerInput
2: $\mathbf{my}$ – IntegerInput
On entry: mx and my must specify ${m}_{x}$ and ${m}_{y}$ respectively, the number of points along the $x$ and $y$ axis that define the rectangular grid.
Constraint:
${\mathbf{mx}}\ge 4$ and ${\mathbf{my}}\ge 4$.
3: $\mathbf{x}\left({\mathbf{mx}}\right)$ – Real (Kind=nag_wp) arrayInput
4: $\mathbf{y}\left({\mathbf{my}}\right)$ – Real (Kind=nag_wp) arrayInput
On entry: ${\mathbf{x}}\left(\mathit{q}\right)$ and ${\mathbf{y}}\left(\mathit{r}\right)$ 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.
Constraints:
${\mathbf{x}}\left(\mathit{q}\right)<{\mathbf{x}}\left(\mathit{q}+1\right)$, for $\mathit{q}=1,2,\dots ,{m}_{x}-1$;
${\mathbf{y}}\left(\mathit{r}\right)<{\mathbf{y}}\left(\mathit{r}+1\right)$, for $\mathit{r}=1,2,\dots ,{m}_{y}-1$.
5: $\mathbf{f}\left({\mathbf{mx}}\times {\mathbf{my}}\right)$ – Real (Kind=nag_wp) arrayInput
On entry: ${\mathbf{f}}\left({m}_{y}\times (\mathit{q}-1)+\mathit{r}\right)$ must contain ${f}_{\mathit{q},\mathit{r}}$, for $\mathit{q}=1,2,\dots ,{m}_{x}$ and $\mathit{r}=1,2,\dots ,{m}_{y}$.
6: $\mathbf{px}$ – IntegerOutput
7: $\mathbf{py}$ – IntegerOutput
On exit: px and py contain ${m}_{x}+4$ and ${m}_{y}+4$, the total number of knots of the computed spline with respect to the $x$ and $y$ variables, respectively.
8: $\mathbf{lamda}\left({\mathbf{mx}}+4\right)$ – Real (Kind=nag_wp) arrayOutput
9: $\mathbf{mu}\left({\mathbf{my}}+4\right)$ – Real (Kind=nag_wp) arrayOutput
On exit: lamda contains the complete set of knots ${\lambda}_{i}$ associated with the $x$ variable, i.e., the interior knots ${\mathbf{lamda}}\left(5\right),{\mathbf{lamda}}\left(6\right),\dots ,{\mathbf{lamda}}\left({\mathbf{px}}-4\right)$, as well as the additional knots
In a similar way, mu contains the set of knots associated with the $y$ variable.
10: $\mathbf{c}\left({\mathbf{mx}}\times {\mathbf{my}}\right)$ – Real (Kind=nag_wp) arrayOutput
On exit: the coefficients of the spline interpolant. ${\mathbf{c}}\left({m}_{y}\times (i-1)+j\right)$ contains the coefficient ${c}_{ij}$ described in Section 3.
11: $\mathbf{wrk}\left(({\mathbf{mx}}+6)\times ({\mathbf{my}}+6)\right)$ – Real (Kind=nag_wp) arrayWorkspace
12: $\mathbf{ifail}$ – IntegerInput/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{mx}}=\u27e8\mathit{\text{value}}\u27e9$.
Constraint: ${\mathbf{mx}}\ge 4$.
On entry, ${\mathbf{my}}=\u27e8\mathit{\text{value}}\u27e9$.
Constraint: ${\mathbf{my}}\ge 4$.
${\mathbf{ifail}}=2$
On entry, the x or the y mesh points are not in strictly ascending order.
${\mathbf{ifail}}=3$
An intermediate set of linear equations is singular – the data is too ill-conditioned to compute $B$-spline coefficients.
${\mathbf{ifail}}=-99$
An unexpected error has been triggered by this routine. Please
contact NAG.
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 main sources of rounding errors are in steps $2$, $3$, $6$ and $7$ of the algorithm described in Section 9.2. It can be shown (see Cox (1975)) that the matrix ${A}_{x}$ formed in step $2$ has elements differing relatively from their true values by at most a small multiple of $3\epsilon $, where $\epsilon $ is the machine precision. ${A}_{x}$ is ‘totally positive’, and a linear system with such a coefficient matrix can be solved quite safely by elimination without pivoting. Similar comments apply to steps $6$ and $7$. Thus the complete process is numerically stable.
8Parallelism and Performance
e01daf 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.
9Further Comments
9.1Timing
The time taken by e01daf is approximately proportional to ${m}_{x}{m}_{y}$.
9.2Outline of Method Used
The process of computing the spline consists of the following steps:
1.choice of the interior $x$-knots ${\lambda}_{5}$, ${\lambda}_{6},\dots ,{\lambda}_{{m}_{x}}$ as ${\lambda}_{\mathit{i}}={x}_{\mathit{i}-2}$, for $\mathit{i}=5,6,\dots ,{m}_{x}$,
2.formation of the system
$${A}_{x}E=F\text{,}$$
where ${A}_{x}$ is a band matrix of order ${m}_{x}$ and bandwidth $4$, containing in its $q$th row the values at ${x}_{q}$ of the B-splines in $x$, ${\mathbf{f}}$ is the ${m}_{x}\times {m}_{y}$ rectangular matrix of values ${f}_{q,r}$, and $E$ denotes an ${m}_{x}\times {m}_{y}$ rectangular matrix of intermediate coefficients,
3.use of Gaussian elimination to reduce this system to band triangular form,
4.solution of this triangular system for $E$,
5.choice of the interior $y$ knots ${\mu}_{5}$, ${\mu}_{6},\dots ,{\mu}_{{m}_{y}}$ as ${\mu}_{\mathit{i}}={y}_{\mathit{i}-2}$, for $\mathit{i}=5,6,\dots ,{m}_{y}$,
where ${A}_{y}$ is the counterpart of ${A}_{x}$ for the $y$ variable, and $C$ denotes the ${m}_{x}\times {m}_{y}$ rectangular matrix of values of ${c}_{ij}$,
7.use of Gaussian elimination to reduce this system to band triangular form,
8.solution of this triangular system for ${C}^{\mathrm{T}}$ and hence $C$.
For computational convenience, steps $2$ and $3$, and likewise steps $6$ and $7$, are combined so that the formation of ${A}_{x}$ and ${A}_{y}$ and the reductions to triangular form are carried out one row at a time.
9.3Evaluation of Computed Spline
The values of the computed spline at the points $({x}_{\mathit{k}},{y}_{\mathit{k}})$, for $\mathit{k}=1,2,\dots ,m$, may be obtained
in the real array ff (see e02def), of length at least $m$, by the following call:
where $\mathtt{M}=m$ and the coordinates ${x}_{k}$, ${y}_{k}$ are stored in $\mathtt{X}\left(k\right)$, $\mathtt{Y}\left(k\right)$.
PX and PY,
LAMDA, MU and C have the same values as
px and pylamda, mu and c output from e01daf.
WRK is a real workspace array of length at least PY, and IWRK is an integer workspace array of length at least $\mathtt{PY}-4$.
(See e02def.)
To evaluate the computed spline on an ${m}_{x}\times {m}_{y}$ rectangular grid of points in the $x$-$y$ plane, which is defined by the $x$ coordinates stored in ${\mathbf{x}}\left(\mathit{j}\right)$, for $\mathit{j}=1,2,\dots ,{m}_{x}$, and the $y$ coordinates stored in ${\mathbf{y}}\left(\mathit{k}\right)$, for $\mathit{k}=1,2,\dots ,{m}_{y}$
, returning the results in the real array ff (see e02dff) which is of length at least ${\mathbf{mx}}\times {\mathbf{my}}$, the following call may be used:
where $\mathtt{MX}={m}_{x}$, $\mathtt{MY}={m}_{y}$.
PX and PY,
LAMDA, MU and C have the same values as
px, py,
lamda, mu and c output from e01daf.
WRK is a real workspace array of length at least $\mathtt{LWRK}=\mathrm{min}\phantom{\rule{0.125em}{0ex}}(\mathit{nwrk1},\mathit{nwrk2})$, for $\mathit{nwrk1}=\mathtt{MX}\times 4+\mathtt{PX}$, $\mathit{nwrk2}=\mathtt{MY}\times 4+\mathtt{PY}$, and IWRK is an integer workspace array of length at least $\mathtt{LIWRK}=\mathtt{MY}+\mathtt{PY}-4$ if $\mathit{nwrk1}>\mathit{nwrk2}$, or $\mathtt{MX}+\mathtt{PX}-4$ otherwise.
The result of the spline evaluated at grid point $(j,k)$ is returned in element ($\mathtt{MY}\times (j-1)+k$) of the array FG.
10Example
This example reads in values of ${m}_{x}$, ${x}_{\mathit{q}}$, for $\mathit{q}=1,2,\dots ,{m}_{x}$, ${m}_{y}$ 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 $({x}_{q},{y}_{r})$.
It then calls e01daf to compute a bicubic spline interpolant of the data values, and prints the values of the knots and B-spline coefficients. Finally it evaluates the spline at a small sample of points on a rectangular grid.