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_nd_scat_shep_eval (e01zn)

## Purpose

nag_interp_nd_scat_shep_eval (e01zn) evaluates the multi-dimensional interpolating function generated by nag_interp_nd_scat_shep (e01zm) and its first partial derivatives.

## Syntax

[q, qx, ifail] = e01zn(x, f, iq, rq, xe, 'd', d, 'm', m, 'n', n)
[q, qx, ifail] = nag_interp_nd_scat_shep_eval(x, f, iq, rq, xe, 'd', d, 'm', m, 'n', n)

## Description

nag_interp_nd_scat_shep_eval (e01zn) takes as input the interpolant Q (x) $Q\left(\mathbf{x}\right)$, xd$\mathbf{x}\in {ℝ}^{d}$ of a set of scattered data points (xr,fr) $\left({\mathbf{x}}_{\mathit{r}},{f}_{\mathit{r}}\right)$, for r = 1,2,,m$\mathit{r}=1,2,\dots ,m$, as computed by nag_interp_nd_scat_shep (e01zm), and evaluates the interpolant and its first partial derivatives at the set of points xi${\mathbf{x}}_{\mathit{i}}$, for i = 1,2,,n$\mathit{i}=1,2,\dots ,n$.
nag_interp_nd_scat_shep_eval (e01zn) must only be called after a call to nag_interp_nd_scat_shep (e01zm).
nag_interp_nd_scat_shep_eval (e01zn) is derived from the new implementation of QS3GRD described by Renka (1988). It uses the modification for high-dimensional interpolation described by Berry and Minser (1999).

## References

Berry M W, Minser K S (1999) Algorithm 798: high-dimensional interpolation using the modified Shepard method ACM Trans. Math. Software 25 353–366
Renka R J (1988) Algorithm 661: QSHEP3D: Quadratic Shepard method for trivariate interpolation of scattered data ACM Trans. Math. Software 14 151–152

## Parameters

### Compulsory Input Parameters

1:     x(d,m) – double array
Note: the i$i$th ordinate of the point xj${x}_{j}$ is stored in x(i,j)${\mathbf{x}}\left(i,j\right)$.
d, the first dimension of the array, must satisfy the constraint d2${\mathbf{d}}\ge 2$.
must be the same array supplied as parameter x in the preceding call to nag_interp_nd_scat_shep (e01zm). It must remain unchanged between calls.
2:     f(m) – double array
m, the dimension of the array, must satisfy the constraint m (d + 1) × (d + 2) / 2 + 2 ${\mathbf{m}}\ge \left({\mathbf{d}}+1\right)×\left({\mathbf{d}}+2\right)/2+2$.
must be the same array supplied as parameter f in the preceding call to nag_interp_nd_scat_shep (e01zm). It must remain unchanged between calls.
3:     iq(2 × m + 1$2×{\mathbf{m}}+1$) – int64int32nag_int array
must be the same array returned as parameter iq in the preceding call to nag_interp_nd_scat_shep (e01zm). It must remain unchanged between calls.
4:     rq(lrq$\mathit{lrq}$) – double array
Note: the dimension of the array rq must be at least ((d + 1) × (d + 2) / 2) × m + 2 × d + 1$\left(\left({\mathbf{d}}+1\right)×\left({\mathbf{d}}+2\right)/2\right)×{\mathbf{m}}+2×{\mathbf{d}}+1$.
must be the same array returned as parameter rq in the preceding call to nag_interp_nd_scat_shep (e01zm). It must remain unchanged between calls.
5:     xe(d,n) – double array
Note: the i$i$th ordinate of the point xj${x}_{j}$ is stored in xe(i,j)${\mathbf{xe}}\left(i,j\right)$.
d, the first dimension of the array, must satisfy the constraint d2${\mathbf{d}}\ge 2$.
xe(1 : d,j)${\mathbf{xe}}\left(1:{\mathbf{d}},\mathit{j}\right)$ must be set to the evaluation point xj${\mathbf{x}}_{\mathit{j}}$, for j = 1,2,,n$\mathit{j}=1,2,\dots ,n$.

### Optional Input Parameters

1:     d – int64int32nag_int scalar
Default: The first dimension of the arrays xe, x. (An error is raised if these dimensions are not equal.)
must be the same value supplied for parameter d in the preceding call to nag_interp_nd_scat_shep (e01zm).
Constraint: d2${\mathbf{d}}\ge 2$.
2:     m – int64int32nag_int scalar
Default: The dimension of the array f and the second dimension of the array x. (An error is raised if these dimensions are not equal.)
must be the same value supplied for parameter m in the preceding call to nag_interp_nd_scat_shep (e01zm).
Constraint: m (d + 1) × (d + 2) / 2 + 2 ${\mathbf{m}}\ge \left({\mathbf{d}}+1\right)×\left({\mathbf{d}}+2\right)/2+2$.
3:     n – int64int32nag_int scalar
Default: The second dimension of the array xe.
n$n$, the number of evaluation points.
Constraint: n1${\mathbf{n}}\ge 1$.

None.

### Output Parameters

1:     q(n) – double array
q(i)${\mathbf{q}}\left(\mathit{i}\right)$ contains the value of the interpolant, at xi${\mathbf{x}}_{\mathit{i}}$, for i = 1,2,,n$\mathit{i}=1,2,\dots ,n$. If any of these evaluation points lie outside the region of definition of the interpolant the corresponding entries in q are set to the largest machine representable number (see nag_machine_real_largest (x02al)), and nag_interp_nd_scat_shep_eval (e01zn) returns with ${\mathbf{ifail}}={\mathbf{3}}$.
2:     qx(d,n) – double array
qx(i,j)${\mathbf{qx}}\left(i,j\right)$ contains the value of the partial derivatives with respect to the i$i$th independent variable (dimension) of the interpolant Q (x) $Q\left(\mathbf{x}\right)$ at xj${\mathbf{x}}_{\mathit{j}}$, for j = 1,2,,n$\mathit{j}=1,2,\dots ,n$, and for each of the partial derivatives i = 1,2,,d$i=1,2,\dots ,d$. If any of these evaluation points lie outside the region of definition of the interpolant, the corresponding entries in qx are set to the largest machine representable number (see nag_machine_real_largest (x02al)), and nag_interp_nd_scat_shep_eval (e01zn) returns with ${\mathbf{ifail}}={\mathbf{3}}$.
3:     ifail – int64int32nag_int scalar
${\mathrm{ifail}}={\mathbf{0}}$ unless the function detects an error (see [Error Indicators and Warnings]).

## Error Indicators and Warnings

ifail = 1${\mathbf{ifail}}=1$
Constraint: d2${\mathbf{d}}\ge 2$.
Constraint: m(d + 1)(d + 2) / 2 + 2${\mathbf{m}}\ge \left({\mathbf{d}}+1\right)\left({\mathbf{d}}+2\right)/2+2$.
Constraint: n1${\mathbf{n}}\ge 1$.
On entry, (d + 1) × (d + 2) / 2 × m + 2 × d + 1$\left({\mathbf{d}}+1\right)×\left({\mathbf{d}}+2\right)/2×{\mathbf{m}}+2×{\mathbf{d}}+1$ exceeds the largest machine integer.
ifail = 2${\mathbf{ifail}}=2$
On entry, values in iq appear to be invalid. Check that iq has not been corrupted between calls to nag_interp_nd_scat_shep (e01zm) and nag_interp_nd_scat_shep_eval (e01zn).
On entry, values in rq appear to be invalid. Check that rq has not been corrupted between calls to nag_interp_nd_scat_shep (e01zm) and nag_interp_nd_scat_shep_eval (e01zn).
ifail = 3${\mathbf{ifail}}=3$
On entry, at least one evaluation point lies outside the region of definition of the interpolant.
ifail = 999${\mathbf{ifail}}=-999$
Dynamic memory allocation failed.

## Accuracy

Computational errors should be negligible in most practical situations.

The time taken for a call to nag_interp_nd_scat_shep_eval (e01zn) will depend in general on the distribution of the data points. If the data points are approximately uniformly distributed, then the time taken should be only O(n)$\mathit{O}\left(n\right)$. At worst O(mn)$\mathit{O}\left(mn\right)$ time will be required.

## Example

```function nag_interp_nd_scat_shep_eval_example
genid = int64(1);
subid = int64(1);
seed = [int64(1762543)];
m = 120; % Number of data points
n = 9; % Number of evaluation points
d = 6; % Number of dimensions

% Initialize the generator to a repeatable sequence
[state, ifail] = nag_rand_init_repeat(genid, subid, seed);

% Generate the data points X
[state, x, ifail] = nag_rand_dist_uniform01(int64(d*m), state);

x = reshape(x, d, m);

% Evaluate f
f = x(1, :).*x(2, :).*x(3, :)./(1+2.*x(4, :).*x(5, :).*x(6, :));

% Generate the interpolant
[iq, rq, ifail] = nag_interp_nd_scat_shep(x, f);

% Generate a set of evaluation points lying on diagonal line.
xe = zeros(d, n);
for i = 1:n
xe(:, i) = i/(n+1);
end

% Evaluate the interpolant
[q, qx, ifail] = nag_interp_nd_scat_shep_eval(x, f, iq, rq, xe);

fprintf('\ni  |  f(i)      q(i)    | |f(i)-q(i)|\n');
fprintf('---|--------------------+--------------\n');
for i=1:n
fun = xe(1, i)*xe(2, i)*xe(3, i)/(1+2*xe(4, i)*xe(5, i)*xe(6, i));
fprintf('%d %10.4f%10.4f %10.4f\n', i, fun, q(i), abs(fun-q(i)));
end
```
```

i  |  f(i)      q(i)    | |f(i)-q(i)|
---|--------------------+--------------
1     0.0010    0.0025     0.0015
2     0.0079    0.0035     0.0043
3     0.0256    0.0213     0.0043
4     0.0567    0.0541     0.0026
5     0.1000    0.0991     0.0009
6     0.1508    0.1528     0.0019
7     0.2034    0.2071     0.0037
8     0.2530    0.2558     0.0028
9     0.2966    0.2941     0.0024

```
```function e01zn_example
genid = int64(1);
subid = int64(1);
seed = [int64(1762543)];
m = 120; % Number of data points
n = 9; % Number of evaluation points
d = 6; % Number of dimensions

% Initialize the generator to a repeatable sequence
[state, ifail] = g05kf(genid, subid, seed);

% Generate the data points X
[state, x, ifail] = g05sa(int64(d*m), state);

x = reshape(x, d, m);

% Evaluate f
f = x(1, :).*x(2, :).*x(3, :)./(1+2.*x(4, :).*x(5, :).*x(6, :));

% Generate the interpolant
[iq, rq, ifail] = e01zm(x, f);

% Generate a set of evaluation points lying on diagonal line.
xe = zeros(d, n);
for i = 1:n
xe(:, i) = i/(n+1);
end

% Evaluate the interpolant
[q, qx, ifail] = e01zn(x, f, iq, rq, xe);

fprintf('\ni  |  f(i)      q(i)    | |f(i)-q(i)|\n');
fprintf('---|--------------------+--------------\n');
for i=1:n
fun = xe(1, i)*xe(2, i)*xe(3, i)/(1+2*xe(4, i)*xe(5, i)*xe(6, i));
fprintf('%d %10.4f%10.4f %10.4f\n', i, fun, q(i), abs(fun-q(i)));
end
```
```

i  |  f(i)      q(i)    | |f(i)-q(i)|
---|--------------------+--------------
1     0.0010    0.0025     0.0015
2     0.0079    0.0035     0.0043
3     0.0256    0.0213     0.0043
4     0.0567    0.0541     0.0026
5     0.1000    0.0991     0.0009
6     0.1508    0.1528     0.0019
7     0.2034    0.2071     0.0037
8     0.2530    0.2558     0.0028
9     0.2966    0.2941     0.0024

```