Integer type:  int32  int64  nag_int  show int32  show int32  show int64  show int64  show nag_int  show nag_int

Chapter Contents
Chapter Introduction
NAG Toolbox

# NAG Toolbox: nag_interp_2d_triang_bary_eval (e01eb)

## Purpose

nag_interp_2d_triang_bary_eval (e01eb) performs barycentric interpolation, at a given set of points, using a set of function values on a scattered grid and a triangulation of that grid computed by nag_interp_2d_triangulate (e01ea).

## Syntax

[pf, ifail] = e01eb(x, y, f, triang, px, py, 'm', m, 'n', n)
[pf, ifail] = nag_interp_2d_triang_bary_eval(x, y, f, triang, px, py, 'm', m, 'n', n)

## Description

nag_interp_2d_triang_bary_eval (e01eb) takes as input a set of scattered data points $\left({x}_{\mathit{r}},{y}_{\mathit{r}},{f}_{\mathit{r}}\right)$, for $\mathit{r}=1,2,\dots ,n$, and a Thiessen triangulation of the $\left({x}_{r},{y}_{r}\right)$ computed by nag_interp_2d_triangulate (e01ea), and interpolates at a set of points $\left({\mathit{px}}_{i},{\mathit{py}}_{i}\right)$, for $\mathit{i}=1,2,\dots ,m$.
If the $i$th interpolation point $\left({\mathit{px}}_{i},{\mathit{py}}_{i}\right)$ is equal to $\left({x}_{r},{y}_{r}\right)$ for some value of $r$, the returned value will be equal to ${f}_{r}$; otherwise a barycentric transformation will be used to calculate the interpolant.
For each point $\left({\mathit{px}}_{i},{\mathit{py}}_{i}\right)$, a triangle is sought which contains the point; the vertices of the triangle and ${f}_{r}$ values at the vertices are then used to compute the value $F\left({\mathit{px}}_{i},{\mathit{py}}_{i}\right)$.
If any interpolation point lies outside the triangulation defined by the input arguments, the returned value is the value provided, ${f}_{s}$, at the closest node $\left({x}_{s},{y}_{s}\right)$.
nag_interp_2d_triang_bary_eval (e01eb) must only be called after a call to nag_interp_2d_triangulate (e01ea).

## References

Cline A K and Renka R L (1984) A storage-efficient 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 triangle-based ${C}^{1}$ interpolation method Rocky Mountain J. Math. 14 223–237

## Parameters

### Compulsory Input Parameters

1:     $\mathrm{x}\left({\mathbf{n}}\right)$ – double array
2:     $\mathrm{y}\left({\mathbf{n}}\right)$ – double array
The coordinates of the $\mathit{r}$th data point, $\left({x}_{r},{y}_{r}\right)$, for $\mathit{r}=1,2,\dots ,n$. x and y must be unchanged from the previous call of nag_interp_2d_triangulate (e01ea).
3:     $\mathrm{f}\left({\mathbf{n}}\right)$ – double array
The function values ${f}_{\mathit{r}}$ at $\left({x}_{\mathit{r}},{y}_{\mathit{r}}\right)$, for $\mathit{r}=1,2,\dots ,n$.
4:     $\mathrm{triang}\left(7×{\mathbf{n}}\right)$int64int32nag_int array
The triangulation computed by the previous call of nag_interp_2d_triangulate (e01ea). See Further Comments in nag_interp_2d_triangulate (e01ea) for details of how the triangulation used is encoded in triang.
5:     $\mathrm{px}\left({\mathbf{m}}\right)$ – double array
6:     $\mathrm{py}\left({\mathbf{m}}\right)$ – double array
The coordinates $\left({\mathit{px}}_{\mathit{i}},{\mathit{py}}_{\mathit{i}}\right)$, for $\mathit{i}=1,2,\dots ,m$, at which interpolated function values are sought.

### Optional Input Parameters

1:     $\mathrm{m}$int64int32nag_int scalar
Default: the dimension of the arrays px, py. (An error is raised if these dimensions are not equal.)
$m$, the number of points to interpolate.
Constraint: ${\mathbf{m}}\ge 1$.
2:     $\mathrm{n}$int64int32nag_int scalar
Default: the dimension of the arrays x, y, f. (An error is raised if these dimensions are not equal.)
$n$, the number of data points. n must be unchanged from the previous call of nag_interp_2d_triangulate (e01ea).
Constraint: ${\mathbf{n}}\ge 3$.

### Output Parameters

1:     $\mathrm{pf}\left({\mathbf{m}}\right)$ – double array
The interpolated values $F\left({\mathit{px}}_{\mathit{i}},{\mathit{py}}_{\mathit{i}}\right)$, for $\mathit{i}=1,2,\dots ,m$.
2:     $\mathrm{ifail}$int64int32nag_int scalar
${\mathbf{ifail}}={\mathbf{0}}$ unless the function detects an error (see Error Indicators and Warnings).

## Error Indicators and Warnings

Errors or warnings detected by the function:
${\mathbf{ifail}}=1$
Constraint: ${\mathbf{n}}\ge 3$.
${\mathbf{ifail}}=2$
Constraint: ${\mathbf{m}}\ge 1$.
${\mathbf{ifail}}=3$
On entry, the triangulation information held in the array triang does not specify a valid triangulation of the data points. triang has been corrupted since the call to nag_interp_2d_triangulate (e01ea).
${\mathbf{ifail}}=4$
At least one evaluation point lies outside the nodal triangulation. For each such point the value returned in pf is that corresponding to a node on the closest boundary line segment.
${\mathbf{ifail}}=-99$
${\mathbf{ifail}}=-399$
Your licence key may have expired or may not have been installed correctly.
${\mathbf{ifail}}=-999$
Dynamic memory allocation failed.

## Accuracy

Not applicable.

The time taken for a call of nag_interp_2d_triang_bary_eval (e01eb) is approximately proportional to the number of interpolation points, $m$.

## Example

See Example in nag_interp_2d_triangulate (e01ea).
```function e01eb_example

fprintf('e01eb example results\n\n');

% Scattered Grid Data
x = [11.16; 12.85; 19.85; 19.72; 15.91;  0.00; 20.87;  3.45; 14.26; ...
17.43; 22.80;  7.58; 25.00;  0.00;  9.66;  5.22; 17.25; 25.00; ...
12.13; 22.23; 11.52; 15.20;  7.54; 17.32;  2.14;  0.51; 22.69; ...
5.47; 21.67;  3.31];
y = [ 1.24;  3.06; 10.72;  1.39;  7.74; 20.00; 20.00; 12.78; 17.87; ...
3.46; 12.39;  1.98; 11.87;  0.00; 20.00; 14.66; 19.57;  3.87; ...
10.79;  6.21;  8.53;  0.00; 10.69; 13.78; 15.03;  8.37; 19.63; ...
17.13; 14.36; 0.33];
f = [22.15; 22.11;  7.97; 16.83; 15.30; 34.60;  5.74; 41.24; 10.74; ...
18.60;  5.47; 29.87;  4.40; 58.20;  4.73; 40.36;  6.43;  8.74; ...
13.71; 10.25; 15.74; 21.60; 19.31; 12.11; 53.10; 49.43;  3.25; ...
28.63;  5.52; 44.08];
% Triangulate on (x,y)
[triang,ifail] = e01ea(x,y);
% Perform barycentric interpolation at (3.0,17.0)
px = 3;
py = 17;
[pf, ifail] = e01eb(x, y, f, triang, px, py);

fprintf('Interpolated value for f at (%4.1f,%4.1f) = %7.2f\n',px,py,pf);

```
```e01eb example results

Interpolated value for f at ( 3.0,17.0) =   39.05
```