# NAG Library Routine Document

## 1Purpose

e01thf evaluates the three-dimensional interpolating function generated by e01tgf and its first partial derivatives.

## 2Specification

Fortran Interface
 Subroutine e01thf ( m, x, y, z, f, iq, liq, rq, lrq, n, u, v, w, q, qx, qy, qz,
 Integer, Intent (In) :: m, iq(liq), liq, lrq, n Integer, Intent (Inout) :: ifail Real (Kind=nag_wp), Intent (In) :: x(m), y(m), z(m), f(m), rq(lrq), u(n), v(n), w(n) Real (Kind=nag_wp), Intent (Out) :: q(n), qx(n), qy(n), qz(n)
#include nagmk26.h
 void e01thf_ (const Integer *m, const double x[], const double y[], const double z[], const double f[], const Integer iq[], const Integer *liq, const double rq[], const Integer *lrq, const Integer *n, const double u[], const double v[], const double w[], double q[], double qx[], double qy[], double qz[], Integer *ifail)

## 3Description

e01thf takes as input the interpolant $Q\left(x,y,z\right)$ of a set of scattered data points $\left({x}_{r},{y}_{r},{z}_{r},{f}_{r}\right)$, for $\mathit{r}=1,2,\dots ,m$, as computed by e01tgf, and evaluates the interpolant and its first partial derivatives at the set of points $\left({u}_{i},{v}_{i},{w}_{i}\right)$, for $\mathit{i}=1,2,\dots ,n$.
e01thf must only be called after a call to e01tgf.
This routine is derived from the routine QS3GRD described by Renka (1988).

## 4References

Renka R J (1988) Algorithm 661: QSHEP3D: Quadratic Shepard method for trivariate interpolation of scattered data ACM Trans. Math. Software 14 151–152

## 5Arguments

1:     $\mathbf{m}$ – IntegerInput
2:     $\mathbf{x}\left({\mathbf{m}}\right)$ – Real (Kind=nag_wp) arrayInput
3:     $\mathbf{y}\left({\mathbf{m}}\right)$ – Real (Kind=nag_wp) arrayInput
4:     $\mathbf{z}\left({\mathbf{m}}\right)$ – Real (Kind=nag_wp) arrayInput
5:     $\mathbf{f}\left({\mathbf{m}}\right)$ – Real (Kind=nag_wp) arrayInput
On entry: m, x, y, z and f must be the same values as were supplied in the preceding call to e01tgf.
6:     $\mathbf{iq}\left({\mathbf{liq}}\right)$ – Integer arrayInput
On entry: must be unchanged from the value returned from a previous call to e01tgf.
7:     $\mathbf{liq}$ – IntegerInput
On entry: the dimension of the array iq as declared in the (sub)program from which e01thf is called.
Constraint: ${\mathbf{liq}}\ge 2×{\mathbf{m}}+1$.
8:     $\mathbf{rq}\left({\mathbf{lrq}}\right)$ – Real (Kind=nag_wp) arrayInput
On entry: must be unchanged from the value returned from a previous call to e01tgf.
9:     $\mathbf{lrq}$ – IntegerInput
On entry: the dimension of the array rq as declared in the (sub)program from which e01thf is called.
Constraint: ${\mathbf{lrq}}\ge 10×{\mathbf{m}}+7$.
10:   $\mathbf{n}$ – IntegerInput
On entry: $n$, the number of evaluation points.
Constraint: ${\mathbf{n}}\ge 1$.
11:   $\mathbf{u}\left({\mathbf{n}}\right)$ – Real (Kind=nag_wp) arrayInput
12:   $\mathbf{v}\left({\mathbf{n}}\right)$ – Real (Kind=nag_wp) arrayInput
13:   $\mathbf{w}\left({\mathbf{n}}\right)$ – Real (Kind=nag_wp) arrayInput
On entry: ${\mathbf{u}}\left(\mathit{i}\right)$, ${\mathbf{v}}\left(\mathit{i}\right)$, ${\mathbf{w}}\left(\mathit{i}\right)$ must be set to the evaluation point $\left({u}_{\mathit{i}},{v}_{\mathit{i}},{w}_{\mathit{i}}\right)$, for $\mathit{i}=1,2,\dots ,n$.
14:   $\mathbf{q}\left({\mathbf{n}}\right)$ – Real (Kind=nag_wp) arrayOutput
On exit: ${\mathbf{q}}\left(\mathit{i}\right)$ contains the value of the interpolant, at $\left({u}_{\mathit{i}},{v}_{\mathit{i}},{w}_{\mathit{i}}\right)$, 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 x02alf), and e01thf returns with ${\mathbf{ifail}}={\mathbf{3}}$.
15:   $\mathbf{qx}\left({\mathbf{n}}\right)$ – Real (Kind=nag_wp) arrayOutput
16:   $\mathbf{qy}\left({\mathbf{n}}\right)$ – Real (Kind=nag_wp) arrayOutput
17:   $\mathbf{qz}\left({\mathbf{n}}\right)$ – Real (Kind=nag_wp) arrayOutput
On exit: ${\mathbf{qx}}\left(\mathit{i}\right)$, ${\mathbf{qy}}\left(\mathit{i}\right)$, ${\mathbf{qz}}\left(\mathit{i}\right)$ contains the value of the partial derivatives of the interpolant $Q\left(x,y,z\right)$ at $\left({u}_{\mathit{i}},{v}_{\mathit{i}},{w}_{\mathit{i}}\right)$, 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 qx, qy and qz are set to the largest machine representable number (see x02alf), and e01thf returns with ${\mathbf{ifail}}={\mathbf{3}}$.
18:   $\mathbf{ifail}$ – IntegerInput/Output
On entry: ifail must be set to $0$, $-1\text{​ or ​}1$. If you are unfamiliar with this argument you should refer to Section 3.4 in How to Use the NAG Library and its Documentation for details.
For environments where it might be inappropriate to halt program execution when an error is detected, the value $-1\text{​ or ​}1$ is recommended. If the output of error messages is undesirable, then the value $1$ is recommended. Otherwise, if you are not familiar with this argument, the recommended value is $0$. When the value $-\mathbf{1}\text{​ or ​}\mathbf{1}$ is used it is essential to test the value of ifail on exit.
On exit: ${\mathbf{ifail}}={\mathbf{0}}$ unless the routine detects an error or a warning has been flagged (see Section 6).

## 6Error Indicators and Warnings

If on entry ${\mathbf{ifail}}=0$ or $-1$, explanatory error messages are output on the current error message unit (as defined by x04aaf).
Errors or warnings detected by the routine:
${\mathbf{ifail}}=1$
 On entry, ${\mathbf{m}}<10$, or ${\mathbf{liq}}<2×{\mathbf{m}}+1$, or ${\mathbf{lrq}}<10×{\mathbf{m}}+7$, or ${\mathbf{n}}<1$.
${\mathbf{ifail}}=2$
Values supplied in iq or rq appear to be invalid. Check that these arrays have not been corrupted between the calls to e01tgf and e01thf.
${\mathbf{ifail}}=3$
At least one evaluation point lies outside the region of definition of the interpolant. At all such points the corresponding values in q, qx, qy and qz have been set to the largest machine representable number (see x02alf).
${\mathbf{ifail}}=-99$
See Section 3.9 in How to Use the NAG Library and its Documentation for further information.
${\mathbf{ifail}}=-399$
Your licence key may have expired or may not have been installed correctly.
See Section 3.8 in How to Use the NAG Library and its Documentation for further information.
${\mathbf{ifail}}=-999$
Dynamic memory allocation failed.
See Section 3.7 in How to Use the NAG Library and its Documentation for further information.

## 7Accuracy

Computational errors should be negligible in most practical situations.

## 8Parallelism and Performance

e01thf is threaded by NAG for parallel execution in multithreaded implementations of the NAG Library.
e01thf 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.
Please consult the X06 Chapter Introduction for information on how to control and interrogate the OpenMP environment used within this routine. Please also consult the Users' Note for your implementation for any additional implementation-specific information.

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

### 9.1Internal Changes

Internal changes have been made to this routine as follows:
• At Mark 26: The algorithm used by this routine, based on a Modified Shepard method, has been changed to produce more reliable results for some data sets which were previously not well handled. In addition, handling of evaluation points which are far away from the original data points has been improved by use of an extrapolation method which returns useful results rather than just an error message as was done at earlier Marks.
• At Mark 26.1: The algorithm has undergone further changes which enable it to work better on certain data sets, for example data presented on a regular grid. The results returned when evaluating the function at points which are not in the original data set used to construct the interpolating function are now likely to be slightly different from those returned at previous Marks of the Library, but the function still interpolates the original data.
For details of all known issues which have been reported for the NAG Library please refer to the Known Issues list.

## 10Example

See Section 10 in e01tgf.
© The Numerical Algorithms Group Ltd, Oxford, UK. 2017