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_5d_scat_shep_eval (e01tn)

## Purpose

nag_interp_5d_scat_shep_eval (e01tn) evaluates the five-dimensional interpolating function generated by nag_interp_5d_scat_shep (e01tm) and its first partial derivatives.

## Syntax

[q, qx, ifail] = e01tn(x, f, iq, rq, xe, 'm', m, 'n', n)
[q, qx, ifail] = nag_interp_5d_scat_shep_eval(x, f, iq, rq, xe, 'm', m, 'n', n)

## Description

nag_interp_5d_scat_shep_eval (e01tn) takes as input the interpolant $Q\left(\mathbf{x}\right)$, $\mathbf{x}\in {ℝ}^{5}$ of a set of scattered data points $\left({\mathbf{x}}_{\mathit{r}},{f}_{\mathit{r}}\right)$, for $\mathit{r}=1,2,\dots ,m$, as computed by nag_interp_5d_scat_shep (e01tm), and evaluates the interpolant and its first partial derivatives at the set of points ${\mathbf{x}}_{\mathit{i}}$, for $\mathit{i}=1,2,\dots ,n$.
nag_interp_5d_scat_shep_eval (e01tn) must only be called after a call to nag_interp_5d_scat_shep (e01tm).
nag_interp_5d_scat_shep_eval (e01tn) is derived from the new implementation of QS3GRD described by Renka (1988). It uses the modification for five-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:     $\mathrm{x}\left(5,{\mathbf{m}}\right)$ – double array
must be the same array supplied as argument x in the preceding call to nag_interp_5d_scat_shep (e01tm). It must remain unchanged between calls.
2:     $\mathrm{f}\left({\mathbf{m}}\right)$ – double array
must be the same array supplied as argument f in the preceding call to nag_interp_5d_scat_shep (e01tm). It must remain unchanged between calls.
3:     $\mathrm{iq}\left(2×{\mathbf{m}}+1\right)$int64int32nag_int array
must be the same array returned as argument iq in the preceding call to nag_interp_5d_scat_shep (e01tm). It must remain unchanged between calls.
4:     $\mathrm{rq}\left(21×{\mathbf{m}}+11\right)$ – double array
must be the same array returned as argument rq in the preceding call to nag_interp_5d_scat_shep (e01tm). It must remain unchanged between calls.
5:     $\mathrm{xe}\left(5,{\mathbf{n}}\right)$ – double array
${\mathbf{xe}}\left(1:5,\mathit{i}\right)$ must be set to the evaluation point ${\mathbf{x}}_{\mathit{i}}$ , for $\mathit{i}=1,2,\dots ,n$.

### Optional Input Parameters

1:     $\mathrm{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 argument m in the preceding call to nag_interp_5d_scat_shep (e01tm).
Constraint: ${\mathbf{m}}\ge 23$.
2:     $\mathrm{n}$int64int32nag_int scalar
Default: the second dimension of the array xe.
$n$, the number of evaluation points.
Constraint: ${\mathbf{n}}\ge 1$.

### Output Parameters

1:     $\mathrm{q}\left({\mathbf{n}}\right)$ – double array
${\mathbf{q}}\left(\mathit{i}\right)$ contains the value of the interpolant, at ${\mathbf{x}}_{\mathit{i}}$, for $\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_5d_scat_shep_eval (e01tn) returns with ${\mathbf{ifail}}={\mathbf{3}}$.
2:     $\mathrm{qx}\left(5,{\mathbf{n}}\right)$ – double array
${\mathbf{qx}}\left(j,i\right)$ contains the value of the partial derivatives with respect to ${\mathbf{x}}_{j}$ of the interpolant $Q\left(\mathbf{x}\right)$ at ${\mathbf{x}}_{\mathit{i}}$, for $\mathit{i}=1,2,\dots ,n$, and for each of the five partial derivatives $j=1,2,3,4,5$. 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_5d_scat_shep_eval (e01tn) returns with ${\mathbf{ifail}}={\mathbf{3}}$.
3:     $\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{m}}\ge 23$.
Constraint: ${\mathbf{n}}\ge 1$.
${\mathbf{ifail}}=2$
On entry, values in iq appear to be invalid. Check that iq has not been corrupted between calls to nag_interp_5d_scat_shep (e01tm) and nag_interp_5d_scat_shep_eval (e01tn).
On entry, values in rq appear to be invalid. Check that rq has not been corrupted between calls to nag_interp_5d_scat_shep (e01tm) and nag_interp_5d_scat_shep_eval (e01tn).
${\mathbf{ifail}}=3$
On entry, at least one evaluation point lies outside the region of definition of the interpolant.
${\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

Computational errors should be negligible in most practical situations.

The time taken for a call to nag_interp_5d_scat_shep_eval (e01tn) 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 $\mathit{O}\left(n\right)$. At worst $\mathit{O}\left(mn\right)$ time will be required.

## Example

This program evaluates the function
 $f x = 1.25 + cos5.4x5 cos6x1 cos6x2 cos6x3 6 + 6 3 x4 - 1 2$
at a set of $30$ randomly generated data points and calls nag_interp_5d_scat_shep (e01tm) to construct an interpolating function $Q\left(\mathbf{x}\right)$. It then calls nag_interp_5d_scat_shep_eval (e01tn) to evaluate the interpolant at a set of random points.
To reduce the time taken by this example, the number of data points is limited to $30$. Increasing this value to the suggested minimum of $4000$ improves the interpolation accuracy at the expense of more time.
```function e01tn_example

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

genid = int64(1);
subid = int64(1);
seed  = [int64(1762543)];
seed2 = [int64(43331)];

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

% Generate the data points x
[state, x, ifail] = g05sa(int64(5*30), state);
x = reshape(x, 5, 30);

% Evaluate function
f = ((1.25+cos(5.4*x(5,:))).*cos(6*x(1,:)).*cos(6*x(2,:)).*cos(6*x(3,:)))./...
(6+6*(3*x(4,:)-1).^2);

% Generate the interpolant
nq = int64(0);
nw = int64(0);
[iq, rq, ifail] = e01tm(x, f, nw, nq);

% Generate repeatable evaluation points
[state, ifail] = g05kf(genid, subid, seed2);
[state, xe, ifail] = g05sa(int64(5*8), state);
xe = reshape(xe, 5, 8);

% Evaluate function at xe
fun = ((1.25+cos(5.4*xe(5,:))).*cos(6*xe(1,:)).*cos(6*xe(2,:)).*...
cos(6*xe(3,:)))./(6+6*(3*xe(4,:)-1).^2);

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

fprintf('\n i |  f(i)       q(i)   |f(i)-q(i)|\n');
fprintf('---|--------------------+---------+\n');
for i=1:8
fprintf(' %d |%8.4f  %8.4f  %8.4f \n', i, fun(i), q(i), abs(fun(i)-q(i)));
end

```
```e01tn example results

i |  f(i)       q(i)   |f(i)-q(i)|
---|--------------------+---------+
1 |  0.0058    0.0464    0.0407
2 |  0.0034    0.4855    0.4821
3 | -0.1096    0.0724    0.1820
4 |  0.0875    0.0320    0.0555
5 |  0.0015    0.0373    0.0358
6 | -0.0158   -0.1170    0.1012
7 |  0.0046   -0.0484    0.0530
8 | -0.0090   -0.0134    0.0043
```