e01 Chapter Contents
e01 Chapter Introduction
NAG Library Manual

# NAG Library Function Documentnag_nd_shep_eval (e01znc)

## 1  Purpose

nag_nd_shep_eval (e01znc) evaluates the multi-dimensional interpolating function generated by nag_nd_shep_interp (e01zmc) and its first partial derivatives.

## 2  Specification

 #include #include
 void nag_nd_shep_eval (Integer d, Integer m, const double x[], const double f[], const Integer iq[], const double rq[], Integer n, const double xe[], double q[], double qx[], NagError *fail)

## 3  Description

nag_nd_shep_eval (e01znc) takes as input the interpolant $Q\left(\mathbf{x}\right)$, $\mathbf{x}\in {ℝ}^{d}$ 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_nd_shep_interp (e01zmc), 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_nd_shep_eval (e01znc) must only be called after a call to nag_nd_shep_interp (e01zmc).
nag_nd_shep_eval (e01znc) 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).

## 4  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

## 5  Arguments

1:     dIntegerInput
On entry: must be the same value supplied for argument d in the preceding call to nag_nd_shep_interp (e01zmc).
Constraint: ${\mathbf{d}}\ge 2$.
2:     mIntegerInput
On entry: must be the same value supplied for argument m in the preceding call to nag_nd_shep_interp (e01zmc).
Constraint: ${\mathbf{m}}\ge \left({\mathbf{d}}+1\right)×\left({\mathbf{d}}+2\right)/2+2$.
3:     x[${\mathbf{d}}×{\mathbf{m}}$]const doubleInput
Note: the $i$th ordinate of the point ${x}_{j}$ is stored in ${\mathbf{x}}\left[\left(j-1\right)×{\mathbf{d}}+i-1\right]$.
On entry: must be the same array supplied as argument x in the preceding call to nag_nd_shep_interp (e01zmc). It must remain unchanged between calls.
4:     f[m]const doubleInput
On entry: must be the same array supplied as argument f in the preceding call to nag_nd_shep_interp (e01zmc). It must remain unchanged between calls.
5:     iq[$2×{\mathbf{m}}+1$]const IntegerInput
On entry: must be the same array returned as argument iq in the preceding call to nag_nd_shep_interp (e01zmc). It must remain unchanged between calls.
6:     rq[$\mathit{dim}$]const doubleInput
Note: the dimension, dim, of the array rq must be at least $\left(\left({\mathbf{d}}+1\right)×\left({\mathbf{d}}+2\right)/2\right)×{\mathbf{m}}+2×{\mathbf{d}}+1$.
On entry: must be the same array returned as argument rq in the preceding call to nag_nd_shep_interp (e01zmc). It must remain unchanged between calls.
7:     nIntegerInput
On entry: $n$, the number of evaluation points.
Constraint: ${\mathbf{n}}\ge 1$.
8:     xe[${\mathbf{d}}×{\mathbf{n}}$]const doubleInput
Note: the $i$th ordinate of the point ${x}_{j}$ is stored in ${\mathbf{xe}}\left[\left(j-1\right)×{\mathbf{d}}+i-1\right]$.
On entry: ${\mathbf{xe}}\left[\left(\mathit{j}-1\right)×{\mathbf{d}}\right],\dots ,{\mathbf{xe}}\left[\left(\mathit{j}-1\right)×{\mathbf{d}}+{\mathbf{d}}-1\right]$ must be set to the evaluation point ${\mathbf{x}}_{\mathit{j}}$, for $\mathit{j}=1,2,\dots ,n$.
9:     q[n]doubleOutput
On exit: ${\mathbf{q}}\left[\mathit{i}-1\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_real_largest_number (X02ALC)), and nag_nd_shep_eval (e01znc) returns with ${\mathbf{fail}}\mathbf{.}\mathbf{code}=$ NE_BAD_POINT.
10:   qx[${\mathbf{d}}×{\mathbf{n}}$]doubleOutput
Note: the $\left(i,j\right)$th element of the matrix is stored in ${\mathbf{qx}}\left[\left(j-1\right)×{\mathbf{d}}+i-1\right]$.
On exit: ${\mathbf{qx}}\left[\left(j-1\right)×{\mathbf{d}}+i-1\right]$ contains the value of the partial derivatives with respect to the $i$th independent variable (dimension) of the interpolant $Q\left(\mathbf{x}\right)$ at ${\mathbf{x}}_{\mathit{j}}$, for $\mathit{j}=1,2,\dots ,n$, and for each of the partial derivatives $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_real_largest_number (X02ALC)), and nag_nd_shep_eval (e01znc) returns with ${\mathbf{fail}}\mathbf{.}\mathbf{code}=$ NE_BAD_POINT.
11:   failNagError *Input/Output
The NAG error argument (see Section 3.6 in the Essential Introduction).

## 6  Error Indicators and Warnings

NE_ALLOC_FAIL
Dynamic memory allocation failed.
On entry, argument $⟨\mathit{\text{value}}⟩$ had an illegal value.
On entry, at least one evaluation point lies outside the region of definition of the interpolant. At all such points the corresponding values in q and qx have been set to ${\mathbf{nag_real_largest_number}}$: ${\mathbf{nag_real_largest_number}}=⟨\mathit{\text{value}}⟩$.
NE_INT
On entry, ${\mathbf{d}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{d}}\ge 2$.
On entry, ${\mathbf{n}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{n}}\ge 1$.
NE_INT_2
On entry, $\left(\left({\mathbf{d}}+1\right)×\left({\mathbf{d}}+2\right)/2\right)×{\mathbf{m}}+2×{\mathbf{d}}+1$ exceeds the largest machine integer.
${\mathbf{d}}=⟨\mathit{\text{value}}⟩$ and ${\mathbf{m}}=⟨\mathit{\text{value}}⟩$.
On entry, ${\mathbf{m}}=⟨\mathit{\text{value}}⟩$ and ${\mathbf{d}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{m}}\ge \left({\mathbf{d}}+1\right)×\left({\mathbf{d}}+2\right)/2+2$.
NE_INT_ARRAY
On entry, values in iq appear to be invalid. Check that iq has not been corrupted between calls to nag_nd_shep_interp (e01zmc) and nag_nd_shep_eval (e01znc).
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.
NE_REAL_ARRAY
On entry, values in rq appear to be invalid. Check that rq has not been corrupted between calls to nag_nd_shep_interp (e01zmc) and nag_nd_shep_eval (e01znc).

## 7  Accuracy

Computational errors should be negligible in most practical situations.

## 8  Parallelism and Performance

nag_nd_shep_eval (e01znc) is threaded by NAG for parallel execution in multithreaded implementations of the NAG Library.
nag_nd_shep_eval (e01znc) makes calls to BLAS and/or LAPACK routines, which may be threaded within the vendor library used by this implementation. Consult the documentation for the vendor library for further information.

The time taken for a call to nag_nd_shep_eval (e01znc) 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.

## 10  Example

This program evaluates the function (in six variables)
 $fx = x1 x2 x3 1 + 2 x4 x5 x6$
at a set of randomly generated data points and calls nag_nd_shep_interp (e01zmc) to construct an interpolating function ${Q}_{x}$. It then calls nag_nd_shep_eval (e01znc) to evaluate the interpolant at a set of points on the line ${x}_{i}=x$, for $\mathit{i}=1,2,\dots ,6$. To reduce the time taken by this example, the number of data points is limited. Increasing this value to the suggested minimum of $4000$ improves the interpolation accuracy at the expense of more time.

### 10.1  Program Text

Program Text (e01znce.c)

### 10.2  Program Data

Program Data (e01znce.d)

### 10.3  Program Results

Program Results (e01znce.r)