E02 Chapter Contents
E02 Chapter Introduction
NAG Library Manual

# NAG Library Routine DocumentE02DCF

Note:  before using this routine, please read the Users' Note for your implementation to check the interpretation of bold italicised terms and other implementation-dependent details.

## 1  Purpose

E02DCF computes a bicubic spline approximation to a set of data values, given on a rectangular grid in the $x$-$y$ plane. The knots of the spline are located automatically, but a single parameter must be specified to control the trade-off between closeness of fit and smoothness of fit.

## 2  Specification

 SUBROUTINE E02DCF ( START, MX, X, MY, Y, F, S, NXEST, NYEST, NX, LAMDA, NY, MU, C, FP, WRK, LWRK, IWRK, LIWRK, IFAIL)
 INTEGER MX, MY, NXEST, NYEST, NX, NY, LWRK, IWRK(LIWRK), LIWRK, IFAIL REAL (KIND=nag_wp) X(MX), Y(MY), F(MX*MY), S, LAMDA(NXEST), MU(NYEST), C((NXEST-4)*(NYEST-4)), FP, WRK(LWRK) CHARACTER(1) START

## 3  Description

E02DCF determines a smooth bicubic spline approximation $s\left(x,y\right)$ to the set of data points $\left({x}_{\mathit{q}},{y}_{\mathit{r}},{f}_{\mathit{q},\mathit{r}}\right)$, 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
 $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}$. For further details, see Hayes and Halliday (1974) for bicubic splines and de Boor (1972) for normalized B-splines.
The total numbers ${n}_{x}$ and ${n}_{y}$ of these knots and their values ${\lambda }_{1},\dots ,{\lambda }_{{n}_{x}}$ and ${\mu }_{1},\dots ,{\mu }_{{n}_{y}}$ are chosen automatically by the routine. The knots ${\lambda }_{5},\dots ,{\lambda }_{{n}_{x}-4}$ and ${\mu }_{5},\dots ,{\mu }_{{n}_{y}-4}$ are the interior knots; they divide the approximation domain $\left[{x}_{1},{x}_{{m}_{x}}\right]×\left[{y}_{1},{y}_{{m}_{y}}\right]$ into $\left({n}_{x}-7\right)×\left({n}_{y}-7\right)$ subpanels $\left[{\lambda }_{\mathit{i}},{\lambda }_{\mathit{i}+1}\right]×\left[{\mu }_{\mathit{j}},{\mu }_{\mathit{j}+1}\right]$, for $\mathit{i}=4,5,\dots ,{n}_{x}-4$ and $\mathit{j}=4,5,\dots ,{n}_{y}-4$. Then, much as in the curve case (see E02BEF), the coefficients ${c}_{\mathit{i}\mathit{j}}$ are determined as the solution of the following constrained minimization problem:
 $minimize⁡η ,$ (2)
subject to the constraint
 $θ = ∑ q=1 mx ∑ r=1 my ε q,r 2 ≤ S ,$ (3)
 where $\eta$ is a measure of the (lack of) smoothness of $s\left(x,y\right)$. Its value depends on the discontinuity jumps in $s\left(x,y\right)$ across the boundaries of the subpanels. It is zero only when there are no discontinuities and is positive otherwise, increasing with the size of the jumps (see Dierckx (1982) for details). ${\epsilon }_{q,r}$ denotes the residual ${f}_{q,r}-s\left({x}_{q},{y}_{r}\right)$, and $S$ is a non-negative number specified by you.
By means of the parameter $S$, ‘the smoothing factor’, you will then control the balance between smoothness and closeness of fit, as measured by the sum of squares of residuals in (3). If $S$ is too large, the spline will be too smooth and signal will be lost (underfit); if $S$ is too small, the spline will pick up too much noise (overfit). In the extreme cases the routine will return an interpolating spline $\left(\theta =0\right)$ if $S$ is set to zero, and the least squares bicubic polynomial $\left(\eta =0\right)$ if $S$ is set very large. Experimenting with $S$-values between these two extremes should result in a good compromise. (See Section 8.3 for advice on choice of $S$.)
The method employed is outlined in Section 8.5 and fully described in Dierckx (1981) and Dierckx (1982). It involves an adaptive strategy for locating the knots of the bicubic spline (depending on the function underlying the data and on the value of $S$), and an iterative method for solving the constrained minimization problem once the knots have been determined.
Values and derivatives of the computed spline can subsequently be computed by calling E02DEF, E02DFF or E02DHF as described in Section 8.6.
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

## 5  Parameters

1:     START – CHARACTER(1)Input
On entry: determines whether calculations are to be performed afresh (Cold Start) or whether knots found in previous calls are to be used as an initial estimate of knot placement (Warm Start).
${\mathbf{START}}=\text{'C'}$
The routine will build up the knot set starting with no interior knots. No values need be assigned to the parameters NX, NY, LAMDA, MU, WRK or IWRK.
${\mathbf{START}}=\text{'W'}$
The routine will restart the knot-placing strategy using the knots found in a previous call of the routine. In this case, the parameters NX, NY, LAMDA, MU, WRK and IWRK must be unchanged from that previous call. This warm start can save much time in determining a satisfactory set of knots for the given value of S. This is particularly useful when different smoothing factors are used for the same dataset.
Constraint: ${\mathbf{START}}=\text{'C'}$ or $\text{'W'}$.
2:     MX – INTEGERInput
On entry: ${m}_{x}$, the number of grid points along the $x$ axis.
Constraint: ${\mathbf{MX}}\ge 4$.
3:     X(MX) – REAL (KIND=nag_wp) arrayInput
On entry: ${\mathbf{X}}\left(\mathit{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}$.
Constraint: ${x}_{1}<{x}_{2}<\cdots <{x}_{{m}_{x}}$.
4:     MY – INTEGERInput
On entry: ${m}_{y}$, the number of grid points along the $y$ axis.
Constraint: ${\mathbf{MY}}\ge 4$.
5:     Y(MY) – 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}$.
Constraint: ${y}_{1}<{y}_{2}<\cdots <{y}_{{m}_{y}}$.
6:     F(${\mathbf{MX}}×{\mathbf{MY}}$) – REAL (KIND=nag_wp) arrayInput
On entry: ${\mathbf{F}}\left({m}_{y}×\left(\mathit{q}-1\right)+\mathit{r}\right)$ must contain the data value ${f}_{\mathit{q},\mathit{r}}$, for $\mathit{q}=1,2,\dots ,{m}_{x}$ and $\mathit{r}=1,2,\dots ,{m}_{y}$.
7:     S – REAL (KIND=nag_wp)Input
On entry: the smoothing factor, $S$.
If ${\mathbf{S}}=0.0$, the routine returns an interpolating spline.
If S is smaller than machine precision, it is assumed equal to zero.
For advice on the choice of S, see Sections 3 and 8.3.
Constraint: ${\mathbf{S}}\ge 0.0$.
8:     NXEST – INTEGERInput
9:     NYEST – INTEGERInput
On entry: an upper bound for the number of knots ${n}_{x}$ and ${n}_{y}$ required in the $x$- and $y$-directions respectively.
In most practical situations, ${\mathbf{NXEST}}={m}_{x}/2$ and ${\mathbf{NYEST}}={m}_{y}/2$ is sufficient. NXEST and NYEST never need to be larger than ${m}_{x}+4$ and ${m}_{y}+4$ respectively, the numbers of knots needed for interpolation $\left({\mathbf{S}}=0.0\right)$. See also Section 8.4.
Constraints:
• ${\mathbf{NXEST}}\ge 8$;
• ${\mathbf{NYEST}}\ge 8$.
10:   NX – INTEGERInput/Output
On entry: if the warm start option is used, the value of NX must be left unchanged from the previous call.
On exit: the total number of knots, ${n}_{x}$, of the computed spline with respect to the $x$ variable.
11:   LAMDA(NXEST) – REAL (KIND=nag_wp) arrayInput/Output
On entry: if the warm start option is used, the values ${\mathbf{LAMDA}}\left(1\right),{\mathbf{LAMDA}}\left(2\right),\dots ,{\mathbf{LAMDA}}\left({\mathbf{NX}}\right)$ must be left unchanged from the previous call.
On exit: 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{NX}}-4\right)$ as well as the additional knots
 $LAMDA1=LAMDA2=LAMDA3=LAMDA4=X1$
and
 $LAMDANX- 3=LAMDANX- 2=LAMDANX- 1=LAMDANX=XMX$
needed for the B-spline representation.
12:   NY – INTEGERInput/Output
On entry: if the warm start option is used, the value of NY must be left unchanged from the previous call.
On exit: the total number of knots, ${n}_{y}$, of the computed spline with respect to the $y$ variable.
13:   MU(NYEST) – REAL (KIND=nag_wp) arrayInput/Output
On entry: if the warm start option is used, the values ${\mathbf{MU}}\left(1\right),{\mathbf{MU}}\left(2\right),\dots ,{\mathbf{MU}}\left({\mathbf{NY}}\right)$ must be left unchanged from the previous call.
On exit: contains the complete set of knots ${\mu }_{i}$ associated with the $y$ variable, i.e., the interior knots ${\mathbf{MU}}\left(5\right),{\mathbf{MU}}\left(6\right),\dots ,{\mathbf{MU}}\left({\mathbf{NY}}-4\right)$ as well as the additional knots
 $MU1=MU2=MU3=MU4=Y1$
and
 $MUNY- 3=MUNY- 2=MUNY- 1=MUNY=YMY$
needed for the B-spline representation.
14:   C($\left({\mathbf{NXEST}}-4\right)×\left({\mathbf{NYEST}}-4\right)$) – REAL (KIND=nag_wp) arrayOutput
On exit: the coefficients of the spline approximation. ${\mathbf{C}}\left(\left({n}_{y}-4\right)×\left(i-1\right)+j\right)$ is the coefficient ${c}_{ij}$ defined in Section 3.
15:   FP – REAL (KIND=nag_wp)Output
On exit: the sum of squared residuals, $\theta$, of the computed spline approximation. If ${\mathbf{FP}}=0.0$, this is an interpolating spline. FP should equal ${\mathbf{S}}$ within a relative tolerance of $0.001$ unless ${\mathbf{NX}}={\mathbf{NY}}=8$, when the spline has no interior knots and so is simply a bicubic polynomial. For knots to be inserted, S must be set to a value below the value of FP produced in this case.
16:   WRK(LWRK) – REAL (KIND=nag_wp) arrayCommunication Array
If the warm start option is used, on entry, the values ${\mathbf{WRK}}\left(1\right),\dots ,{\mathbf{WRK}}\left(4\right)$ must be left unchanged from the previous call.
This array is used as workspace.
17:   LWRK – INTEGERInput
On entry: the dimension of the array WRK as declared in the (sub)program from which E02DCF is called.
Constraint: ${\mathbf{LWRK}}\ge 4×\left({\mathbf{MX}}+{\mathbf{MY}}\right)+11×\left({\mathbf{NXEST}}+{\mathbf{NYEST}}\right)+{\mathbf{NXEST}}×{\mathbf{MY}}+\phantom{\rule{0ex}{0ex}}\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left({\mathbf{MY}},{\mathbf{NXEST}}\right)+54$.
18:   IWRK(LIWRK) – INTEGER arrayCommunication Array
If the warm start option is used, on entry, the values ${\mathbf{IWRK}}\left(1\right),\dots ,{\mathbf{IWRK}}\left(3\right)$ must be left unchanged from the previous call.
This array is used as workspace.
19:   LIWRK – INTEGERInput
On entry: the dimension of the array IWRK as declared in the (sub)program from which E02DCF is called.
Constraint: ${\mathbf{LIWRK}}\ge 3+{\mathbf{MX}}+{\mathbf{MY}}+{\mathbf{NXEST}}+{\mathbf{NYEST}}$.
20:   IFAIL – INTEGERInput/Output
On entry: IFAIL must be set to $0$, $-1\text{​ or ​}1$. If you are unfamiliar with this parameter you should refer to Section 3.3 in the Essential Introduction for details.
For environments where it might be inappropriate to halt program execution when an error is detected, the value $-1\text{​ or ​}1$ is recommended. If the output of error messages is undesirable, then the value $1$ is recommended. Otherwise, if you are not familiar with this parameter, the recommended value is $0$. When the value $-\mathbf{1}\text{​ 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).

## 6  Error Indicators and Warnings

If on entry ${\mathbf{IFAIL}}={\mathbf{0}}$ or $-{\mathbf{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{START}}\ne \text{'C'}$ or $\text{'W'}$, or ${\mathbf{MX}}<4$, or ${\mathbf{MY}}<4$, or ${\mathbf{S}}<0.0$, or ${\mathbf{S}}=0.0$ and ${\mathbf{NXEST}}<{\mathbf{MX}}+4$, or ${\mathbf{S}}=0.0$ and ${\mathbf{NYEST}}<{\mathbf{MY}}+4$, or ${\mathbf{NXEST}}<8$, or ${\mathbf{NYEST}}<8$, or ${\mathbf{LWRK}}<4×\left({\mathbf{MX}}+{\mathbf{MY}}\right)+11×\left({\mathbf{NXEST}}+{\mathbf{NYEST}}\right)+{\mathbf{NXEST}}×{\mathbf{MY}}+\phantom{\rule{0ex}{0ex}}\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left({\mathbf{MY}},{\mathbf{NXEST}}\right)+54$, or ${\mathbf{LIWRK}}<3+{\mathbf{MX}}+{\mathbf{MY}}+{\mathbf{NXEST}}+{\mathbf{NYEST}}$.
${\mathbf{IFAIL}}=2$
The values of ${\mathbf{X}}\left(\mathit{q}\right)$, for $\mathit{q}=1,2,\dots ,{\mathbf{MX}}$, are not in strictly increasing order.
${\mathbf{IFAIL}}=3$
The values of ${\mathbf{Y}}\left(\mathit{r}\right)$, for $\mathit{r}=1,2,\dots ,{\mathbf{MY}}$, are not in strictly increasing order.
${\mathbf{IFAIL}}=4$
The number of knots required is greater than allowed by NXEST and NYEST. Try increasing NXEST and/or NYEST and, if necessary, supplying larger arrays for the parameters LAMDA, MU, C, WRK and IWRK. However, if NXEST and NYEST are already large, say ${\mathbf{NXEST}}>{\mathbf{MX}}/2$ and ${\mathbf{NYEST}}>{\mathbf{MY}}/2$, then this error exit may indicate that S is too small.
${\mathbf{IFAIL}}=5$
The iterative process used to compute the coefficients of the approximating spline has failed to converge. This error exit may occur if S has been set very small. If the error persists with increased S, contact NAG.
If ${\mathbf{IFAIL}}={\mathbf{4}}$ or ${\mathbf{5}}$, a spline approximation is returned, but it fails to satisfy the fitting criterion (see (2) and (3) in Section 3) – perhaps by only a small amount, however.

## 7  Accuracy

On successful exit, the approximation returned is such that its sum of squared residuals FP is equal to the smoothing factor ${\mathbf{S}}$, up to a specified relative tolerance of $0.001$ – except that if ${n}_{x}=8$ and ${n}_{y}=8$, FP may be significantly less than ${\mathbf{S}}$: in this case the computed spline is simply the least squares bicubic polynomial approximation of degree $3$, i.e., a spline with no interior knots.

### 8.1  Timing

The time taken for a call of E02DCF depends on the complexity of the shape of the data, the value of the smoothing factor $S$, and the number of data points. If E02DCF is to be called for different values of $S$, much time can be saved by setting ${\mathbf{START}}=\text{'W'}$ after the first call.

### 8.2  Weighting of Data Points

E02DCF does not allow individual weighting of the data values. If these were determined to widely differing accuracies, it may be better to use E02DDF. The computation time would be very much longer, however.

### 8.3  Choice of S

If the standard deviation of ${f}_{q,r}$ is the same for all $q$ and $r$ (the case for which E02DCF is designed – see Section 8.2.) and known to be equal, at least approximately, to $\sigma$, say, then following Reinsch (1967) and choosing the parameter S in the range ${\sigma }^{2}\left(m±\sqrt{2m}\right)$, where $m={m}_{x}{m}_{y}$, is likely to give a good start in the search for a satisfactory value. If the standard deviations vary, the sum of their squares over all the data points could be used. Otherwise experimenting with different values of S will be required from the start, taking account of the remarks in Section 3.
In that case, in view of computation time and memory requirements, it is recommended to start with a very large value for S and so determine the least squares bicubic polynomial; the value returned for FP, call it ${{\mathbf{FP}}}_{0}$, gives an upper bound for S. Then progressively decrease the value of S to obtain closer fits – say by a factor of $10$ in the beginning, i.e., ${\mathbf{S}}={{\mathbf{FP}}}_{0}/10$, ${\mathbf{S}}={{\mathbf{FP}}}_{0}/100$, and so on, and more carefully as the approximation shows more details.
The number of knots of the spline returned, and their location, generally depend on the value of ${\mathbf{S}}$ and on the behaviour of the function underlying the data. However, if E02DCF is called with ${\mathbf{START}}=\text{'W'}$, the knots returned may also depend on the smoothing factors of the previous calls. Therefore if, after a number of trials with different values of ${\mathbf{S}}$ and ${\mathbf{START}}=\text{'W'}$, a fit can finally be accepted as satisfactory, it may be worthwhile to call E02DCF once more with the selected value for ${\mathbf{S}}$ but now using ${\mathbf{START}}=\text{'C'}$. Often, E02DCF then returns an approximation with the same quality of fit but with fewer knots, which is therefore better if data reduction is also important.

### 8.4  Choice of NXEST and NYEST

The number of knots may also depend on the upper bounds NXEST and NYEST. Indeed, if at a certain stage in E02DCF the number of knots in one direction (say ${n}_{x}$) has reached the value of its upper bound (NXEST), then from that moment on all subsequent knots are added in the other $\left(y\right)$ direction. Therefore you have the option of limiting the number of knots the routine locates in any direction. For example, by setting ${\mathbf{NXEST}}=8$ (the lowest allowable value for NXEST), you can indicate that you want an approximation which is a simple cubic polynomial in the variable $x$.

### 8.5  Outline of Method Used

If $S=0$, the requisite number of knots is known in advance, i.e., ${n}_{x}={m}_{x}+4$ and ${n}_{y}={m}_{y}+4$; the interior knots are located immediately as ${\lambda }_{\mathit{i}}={x}_{\mathit{i}-2}$ and ${\mu }_{\mathit{j}}={y}_{\mathit{j}-2}$, for $\mathit{i}=5,6,\dots ,{n}_{x}-4$ and $\mathit{j}=5,6,\dots ,{n}_{y}-4$. The corresponding least squares spline is then an interpolating spline and therefore a solution of the problem.
If $S>0$, suitable knot sets are built up in stages (starting with no interior knots in the case of a cold start but with the knot set found in a previous call if a warm start is chosen). At each stage, a bicubic spline is fitted to the data by least squares, and $\theta$, the sum of squares of residuals, is computed. If $\theta >S$, new knots are added to one knot set or the other so as to reduce $\theta$ at the next stage. The new knots are located in intervals where the fit is particularly poor, their number depending on the value of $S$ and on the progress made so far in reducing $\theta$. Sooner or later, we find that $\theta \le S$ and at that point the knot sets are accepted. The routine then goes on to compute the (unique) spline which has these knot sets and which satisfies the full fitting criterion specified by (2) and (3). The theoretical solution has $\theta =S$. The routine computes the spline by an iterative scheme which is ended when $\theta =S$ within a relative tolerance of $0.001$. The main part of each iteration consists of a linear least squares computation of special form, done in a similarly stable and efficient manner as in E02BAF for least squares curve-fitting.
An exception occurs when the routine finds at the start that, even with no interior knots $\left({n}_{x}={n}_{y}=8\right)$, the least squares spline already has its sum of residuals $\text{}\le S$. In this case, since this spline (which is simply a bicubic polynomial) also has an optimal value for the smoothness measure $\eta$, namely zero, it is returned at once as the (trivial) solution. It will usually mean that $S$ has been chosen too large.
For further details of the algorithm and its use see Dierckx (1982).

### 8.6  Evaluation of Computed Spline

The values of the computed spline at the points $\left({x}_{\mathit{r}},{y}_{\mathit{r}}\right)$, for $\mathit{r}=1,2,\dots ,m$, may be obtained in the real array FF (see E02DEF), of length at least $m$, by the following call:
```IFAIL = 0
CALL E02DEF(M,PX,PY,X,Y,LAMDA,MU,C,FF,WRK,IWRK,IFAIL)
```
where $\mathtt{M}=m$ and the coordinates ${x}_{r}$, ${y}_{r}$ are stored in $\mathtt{X}\left(k\right)$, $\mathtt{Y}\left(k\right)$. PX and PY have the same values as NX and NY as output from E02DCF, and LAMDA, MU and C have the same values as LAMDA, MU and C output from E02DCF. WRK is a real workspace array of length at least $\mathtt{PY}-4$, and IWRK is an integer workspace array of length at least $\mathtt{PY}-4$.
To evaluate the computed spline on a ${m}_{x}$ by ${m}_{y}$ rectangular grid of points in the $x$-$y$ plane, which is defined by the $x$ coordinates stored in $\mathtt{X}\left(\mathit{q}\right)$, for $\mathit{q}=1,2,\dots ,{m}_{x}$, and the $y$ coordinates stored in $\mathtt{Y}\left(\mathit{r}\right)$, for $\mathit{r}=1,2,\dots ,{m}_{y}$, returning the results in the real array FF (see E02DFF) which is of length at least ${\mathbf{MX}}×{\mathbf{MY}}$, the following call may be used:
``` IFAIL = 0
CALL E02DFF(MX,MY,PX,PY,X,Y,LAMDA,MU,C,FG,WRK,LWRK,
*            IWRK,LIWRK,IFAIL)
```
where $\mathtt{MX}={m}_{x}$, $\mathtt{MY}={m}_{y}$. PX and PY have the same values as NX and NY as output from E02DCF, and LAMDA, MU and C have the same values as LAMDA, MU and C output from E02DCF. WRK is a real workspace array of length at least $\mathtt{LWRK}=\mathrm{min}\phantom{\rule{0.125em}{0ex}}\left(\mathit{nwrk1},\mathit{nwrk2}\right)$, where $\mathit{nwrk1}=\mathtt{MX}×4+\mathtt{PX}$ and $\mathit{nwrk2}=\mathtt{MY}×4+\mathtt{PY}$. IWRK is an integer workspace array of length at least $\mathtt{LIWRK}=\mathtt{MY}+\mathtt{PY}-4$ if $\mathit{nwrk1}\ge \mathit{nwrk2}$, or $\mathtt{MX}+\mathtt{PX}-4$ otherwise.
The result of the spline evaluated at grid point $\left(q,r\right)$ is returned in element $\left(\mathtt{MY}×\left(q-1\right)+r\right)$ of the array FG.

## 9  Example

This example reads in values of MX, MY, ${x}_{\mathit{q}}$, for $\mathit{q}=1,2,\dots ,{\mathbf{MX}}$, and ${y}_{\mathit{r}}$, for $\mathit{r}=1,2,\dots ,{\mathbf{MY}}$, 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, and prints the values of the computed knots and B-spline coefficients. Finally it evaluates the spline at a small sample of points on a rectangular grid.

### 9.1  Program Text

Program Text (e02dcfe.f90)

### 9.2  Program Data

Program Data (e02dcfe.d)

### 9.3  Program Results

Program Results (e02dcfe.r)