NAG Library Function Document
nag_2d_triang_interp (e01sjc)
1 Purpose
nag_2d_triang_interp (e01sjc) generates a twodimensional surface interpolating a set of scattered data points, using the method of Renka and Cline.
2 Specification
#include <nag.h> 
#include <nage01.h> 
void 
nag_2d_triang_interp (Integer m,
const double x[],
const double y[],
const double f[],
Integer triang[],
double grads[],
NagError *fail) 

3 Description
nag_2d_triang_interp (e01sjc) constructs an interpolating surface $F\left(x,y\right)$ through a set of $m$ scattered data points $\left({x}_{\mathit{r}},{y}_{\mathit{r}},{f}_{\mathit{r}}\right)$, for $\mathit{r}=1,2,\dots ,m$, using a method due to Renka and Cline. In the $\left(x,y\right)$ plane, the data points must be distinct. The constructed surface is continuous and has continuous first derivatives.
The method involves firstly creating a triangulation with all the
$\left(x,y\right)$ data points as nodes, the triangulation being as nearly equiangular as possible (see
Cline and Renka (1984)). Then gradients in the
$x$ and
$y$directions are estimated at node
$\mathit{r}$, for
$\mathit{r}=1,2,\dots ,m$,
as the partial derivatives of a quadratic function of
$x$ and
$y$ which interpolates the data value
${f}_{r}$,
and which fits the data values at nearby nodes (those within a certain distance chosen by the algorithm) in a weighted least squares sense. The weights are chosen such that closer nodes have more influence than more distant nodes on derivative estimates at node
$r$. The computed partial derivatives, with the
${f}_{r}$ values, at the three nodes of each triangle define a piecewise polynomial surface of a certain form which is the interpolant on that triangle. See
Renka and Cline (1984) for more detailed information on the algorithm,
a development of that by
Lawson (1977). The code is derived from
Renka (1984).
The interpolant
$F\left(x,y\right)$ can subsequently be evaluated at any point
$\left(x,y\right)$ inside or outside the domain of the data by a call to
nag_2d_triang_eval (e01skc).
Points outside the domain are evaluated by extrapolation.
4 References
Cline A K and Renka R L (1984) A storageefficient method for construction of a Thiessen triangulation Rocky Mountain J. Math. 14 119–139
Lawson C L (1977) Software for ${C}^{1}$ surface interpolation Mathematical Software III (ed J R Rice) 161–194 Academic Press
Renka R L (1984) Algorithm 624: triangulation and interpolation of arbitrarily distributed points in the plane ACM Trans. Math. Software 10 440–442
Renka R L and Cline A K (1984) A trianglebased ${C}^{1}$ interpolation method Rocky Mountain J. Math. 14 223–237
5 Arguments
 1:
$\mathbf{m}$ – IntegerInput

On entry: $m$, the number of data points.
Constraint:
${\mathbf{m}}\ge 3$.
 2:
$\mathbf{x}\left[{\mathbf{m}}\right]$ – const doubleInput
 3:
$\mathbf{y}\left[{\mathbf{m}}\right]$ – const doubleInput
 4:
$\mathbf{f}\left[{\mathbf{m}}\right]$ – const doubleInput

On entry: the coordinates of the
$\mathit{r}$th data point, for
$\mathit{r}=1,2,\dots ,m$. The data points are accepted in any order, but see
Section 9.
Constraint:
the $\left(x,y\right)$ nodes must not all be collinear, and each node must be unique.
 5:
$\mathbf{triang}\left[7\times {\mathbf{m}}\right]$ – IntegerOutput

On exit: a data structure defining the computed triangulation, in a form suitable for passing to
nag_2d_triang_eval (e01skc).
 6:
$\mathbf{grads}\left[2\times {\mathbf{m}}\right]$ – doubleOutput

Note: the $\left(i,j\right)$th element of the matrix is stored in ${\mathbf{grads}}\left[\left(j1\right)\times 2+i1\right]$.
On exit: the estimated partial derivatives at the nodes, in a form suitable for passing to
nag_2d_triang_eval (e01skc). The derivatives at node
$\mathit{r}$ with respect to
$x$ and
$y$ are contained in
${\mathbf{grads}}\left[\left(\mathit{r}1\right)\times 2\right]$ and
${\mathbf{grads}}\left[\left(\mathit{r}1\right)\times 2+1\right]$ respectively, for
$\mathit{r}=1,2,\dots ,m$.
 7:
$\mathbf{fail}$ – NagError *Input/Output

The NAG error argument (see
Section 3.6 in the Essential Introduction).
6 Error Indicators and Warnings
 NE_ALL_DATA_COLLINEAR

All nodes are collinear. There is no unique solution.
 NE_ALLOC_FAIL

Dynamic memory allocation failed.
See
Section 3.2.1.2 in the Essential Introduction for further information.
 NE_BAD_PARAM

On entry, argument $\u2329\mathit{\text{value}}\u232a$ had an illegal value.
 NE_DATA_NOT_UNIQUE

On entry, $\left({\mathbf{x}}\left[\mathit{I}1\right],{\mathbf{y}}\left[\mathit{I}1\right]\right)=\left({\mathbf{x}}\left[\mathit{J}1\right],{\mathbf{y}}\left[\mathit{J}1\right]\right)$, for $\mathit{I},\mathit{J}=\u2329\mathit{\text{value}}\u232a\u2329\mathit{\text{value}}\u232a$, ${\mathbf{x}}\left[\mathit{I}1\right]$, ${\mathbf{y}}\left[\mathit{I}1\right]=\u2329\mathit{\text{value}}\u232a\u2329\mathit{\text{value}}\u232a$.
 NE_INT

On entry, ${\mathbf{m}}=\u2329\mathit{\text{value}}\u232a$.
Constraint: ${\mathbf{m}}\ge 3$.
 NE_INTERNAL_ERROR

An internal error has occurred in this function. Check the function call and any array sizes. If the call is correct then please contact
NAG for assistance.
An unexpected error has been triggered by this function. Please contact
NAG.
See
Section 3.6.6 in the Essential Introduction for further information.
 NE_NO_LICENCE

Your licence key may have expired or may not have been installed correctly.
See
Section 3.6.5 in the Essential Introduction for further information.
7 Accuracy
On successful exit, the computational errors should be negligible in most situations but you should always check the computed surface for acceptability, by drawing contours for instance. The surface always interpolates the input data exactly.
8 Parallelism and Performance
Not applicable.
The time taken for a call of nag_2d_triang_interp (e01sjc) is approximately proportional to the number of data points,
$m$. The function is more efficient if, before entry, the values in
x,
y and
f are arranged so that the
x array is in ascending order.
10 Example
This example reads in a set of
$30$ data points and calls nag_2d_triang_interp (e01sjc)
to construct an interpolating surface. It then calls
nag_2d_triang_eval (e01skc)
to evaluate the interpolant at a sample of points on a rectangular grid.
Note that this example is not typical of a realistic problem: the number of data points would normally be larger, and the interpolant would need to be evaluated on a finer grid to obtain an accurate plot, say.
10.1 Program Text
Program Text (e01sjce.c)
10.2 Program Data
Program Data (e01sjce.d)
10.3 Program Results
Program Results (e01sjce.r)