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

PDF version (NAG web site, 64-bit version, 64-bit version)
Chapter Contents
Chapter Introduction
NAG Toolbox

# NAG Toolbox: nag_interp_4d_scat_shep_eval (e01tl)

## Purpose

nag_interp_4d_scat_shep_eval (e01tl) evaluates the four-dimensional interpolating function generated by nag_interp_4d_scat_shep (e01tk) and its first partial derivatives.

## Syntax

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

## Description

nag_interp_4d_scat_shep_eval (e01tl) takes as input the interpolant Q (x) $Q\left(\mathbf{x}\right)$, x4$x\in {ℝ}^{4}$ 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_4d_scat_shep (e01tk), and evaluates the interpolant and its first partial derivatives at the set of points xi ${\mathbf{x}}_{i}$, for i = 1,2,,n$\mathit{i}=1,2,\dots ,n$.
nag_interp_4d_scat_shep_eval (e01tl) must only be called after a call to nag_interp_4d_scat_shep (e01tk).
nag_interp_4d_scat_shep_eval (e01tl) 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(4$4$,m) – double array
Note: the coordinates of xr${x}_{r}$ are stored in x(1,r) x(4,r) ${\mathbf{x}}\left(1,r\right)\dots {\mathbf{x}}\left(4,r\right)$.
must be the same array supplied as parameter x in the preceding call to nag_interp_4d_scat_shep (e01tk). It must remain unchanged between calls.
2:     f(m) – double array
m, the dimension of the array, must satisfy the constraint m16${\mathbf{m}}\ge 16$.
must be the same array supplied as parameter f in the preceding call to nag_interp_4d_scat_shep (e01tk). 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_4d_scat_shep (e01tk). It must remain unchanged between calls.
4:     rq(15 × m + 9$15×{\mathbf{m}}+9$) – double array
must be the same array returned as parameter rq in the preceding call to nag_interp_4d_scat_shep (e01tk). It must remain unchanged between calls.
5:     xe(4$4$,n) – double array
xe(1 : 4,i)${\mathbf{xe}}\left(1:4,\mathit{i}\right)$ must be set to the evaluation point xi${\mathbf{x}}_{\mathit{i}}$ , for i = 1,2,,n$\mathit{i}=1,2,\dots ,n$.

### Optional Input Parameters

1:     m – int64int32nag_int scalar
Default: The dimension of the array f and the first 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_4d_scat_shep (e01tk).
Constraint: m16${\mathbf{m}}\ge 16$.
2:     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_4d_scat_shep_eval (e01tl) returns with ${\mathbf{ifail}}={\mathbf{3}}$.
2:     qx(4$4$,n) – double array
qx(j,i)${\mathbf{qx}}\left(j,i\right)$ contains the value of the partial derivatives with respect to xj${\mathbf{x}}_{j}$ of the interpolant Q (x) $Q\left(\mathbf{x}\right)$ at xi${\mathbf{x}}_{\mathit{i}}$, for i = 1,2,,n$\mathit{i}=1,2,\dots ,n$, and for each of the four partial derivatives j = 1,2,3,4$j=1,2,3,4$. 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_4d_scat_shep_eval (e01tl) 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

Errors or warnings detected by the function:
ifail = 1${\mathbf{ifail}}=1$
Constraint: m16${\mathbf{m}}\ge 16$.
Constraint: n1${\mathbf{n}}\ge 1$.
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_4d_scat_shep (e01tk) and nag_interp_4d_scat_shep_eval (e01tl).
On entry, values in rq appear to be invalid. Check that rq has not been corrupted between calls to nag_interp_4d_scat_shep (e01tk) and nag_interp_4d_scat_shep_eval (e01tl).
ifail = 3${\mathbf{ifail}}=3$
On entry, at least one evaluation point lies outside the region of definition of the interpolant.

## Accuracy

Computational errors should be negligible in most practical situations.

The time taken for a call to nag_interp_4d_scat_shep_eval (e01tl) 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_4d_scat_shep_eval_example
genid = int64(1);
subid = int64(1);
seed  = [int64(1762543)];
seed2 = [int64(43331)];

% 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(120), state);

% Put x into the right shape for the e01 routines
x = reshape(x, 4, 30);

% Create function values
c1 = cos(6*x(1,:));
c2 = cos(6*x(2,:));
c3 = 6 + 6*(3*x(3,:)-1).^2;
c4 = 1.25 + cos(5.4*x(4,:));
f  = c4.*c1.*c2./c3;

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

% Generate repeatable evaluation points
[state, ifail] = nag_rand_init_repeat(genid, subid, seed2);
[state, xe, ifail] = nag_rand_dist_uniform01(int64(32), state);
xe = reshape(xe, 4, 8);

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

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

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
```
```

i |  f(i)       q(i)   |f(i)-q(i)|
---|--------------------+---------+
1 | -0.0189   -0.0394    0.0205
2 | -0.0186    0.0967    0.1153
3 |  0.1147    0.0606    0.0541
4 |  0.0096   -0.1313    0.1409
5 | -0.1354   -0.1878    0.0524
6 |  0.0022   -0.1595    0.1617
7 | -0.0095   -0.1179    0.1084
8 |  0.0113   -0.3950    0.4063

```
```function e01tl_example
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(120), state);

% Put x into the right shape for the e01 routines
x = reshape(x, 4, 30);

% Create function values
c1 = cos(6*x(1,:));
c2 = cos(6*x(2,:));
c3 = 6 + 6*(3*x(3,:)-1).^2;
c4 = 1.25 + cos(5.4*x(4,:));
f  = c4.*c1.*c2./c3;

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

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

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

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

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
```
```

i |  f(i)       q(i)   |f(i)-q(i)|
---|--------------------+---------+
1 | -0.0189   -0.0394    0.0205
2 | -0.0186    0.0967    0.1153
3 |  0.1147    0.0606    0.0541
4 |  0.0096   -0.1313    0.1409
5 | -0.1354   -0.1878    0.0524
6 |  0.0022   -0.1595    0.1617
7 | -0.0095   -0.1179    0.1084
8 |  0.0113   -0.3950    0.4063

```

PDF version (NAG web site, 64-bit version, 64-bit version)
Chapter Contents
Chapter Introduction
NAG Toolbox

© The Numerical Algorithms Group Ltd, Oxford, UK. 2009–2013