NAG CL Interface
e01zac (dimn_​grid)

Settings help

CL Name Style:


1 Purpose

e01zac interpolates data at a point in n-dimensional space, that is defined by a set of gridded data points. It offers three methods to interpolate the data: Linear Interpolation, Cubic Interpolation and Weighted Average.

2 Specification

#include <nag.h>
void  e01zac (Integer d, const Integer narr[], Nag_Boolean uniform, const double axis[], Integer lx, const double v[], const double point[], Nag_Interp method, Integer k, double wf, double *ans, NagError *fail)
The function may be called by the names: e01zac, nag_interp_dimn_grid or nag_nd_grid_interp.

3 Description

e01zac interpolates an n-dimensional point within a set of gridded data points, Z= {z1j1,z2j2,,zdjd} , with corresponding data values F= {f1j1,f2j2,,fdjd} where, for the ith dimension, ji=1,,ni and ni is the number of ordinates in the ith dimension.
A hypercube of (2k)d data points [h1,h2,,h(2k)d]Z, where hi=(hi1,hi2,,hid) and the corresponding data values are f(hi)F, around the given point, x=(x1,x2,,xd), is found and then used to interpolate using one of the following three methods.
  1. (i)Weighted Average, that is a modification of Shepard's method (Shepard (1968)) as used for scattered data in e01zmc. This method interpolates the data with the weighted mean
    Q (x) = r=1 (2k)d wr (x) fr r=1 (2k)d wr (x) ,  
    where fr=f(hr), wr (x) = 1 D (|x-hr|) and D (y) = y1ρ+y2ρ++ydρ, for a given value of ρ.
  2. (ii)Linear Interpolation, which takes 2d surrounding data points (k=1) and performs two one-dimensional linear interpolations in each dimension on data points ha and hb, reducing the dimension every iteration until it has reached an answer. The formula for linear interpolation in dimension i is simply
    f = fa + (xi-hai) fb-fa hbi-hai ,  
    where fr=f(hr) and hai<xi<hbi.
  3. (iii)Cubic Interpolation, based on cubic convolution (Keys (1981)). In a similar way to the Linear Interpolation method, it performs the interpolations in one dimension reducing it each time, however it requires four surrounding data points in each dimension (k=2), two in each direction (h−1,h0,h1,h2). The following is used to calculate the one-dimensional interpolant in dimension i
    f = 12 ( 1 t t2 t3 ) ( 0 2 0 0 −1 0 1 0 2 −5 4 −1 −1 3 −3 1 ) ( f−1 f0 f1 f2 )  
    where t=xi-h0i and fr=f(hr).

4 References

Keys R (1981) Cubic Convolution Interpolation for Digital Image Processing IEEE Transactions on Acoutstics, Speech, and Signal Processing Vol ASSP-29 No. 6 1153–1160 http://hmi.stanford.edu/doc/Tech_Notes/HMI-TN-2004-004-Interpolation/Keys_cubic_interp.pdf
Shepard D (1968) A two-dimensional interpolation function for irregularly spaced data Proc. 23rd Nat. Conf. ACM 517–523 Brandon/Systems Press Inc., Princeton

5 Arguments

1: d Integer Input
On entry: d, the number of dimensions.
Constraint: d2.
2: narr[d] const Integer Input
On entry: the number of data ordinates in each dimension, with narr[i-1]=ni, for i=1,2,,d.
Constraint: narr[i-1]2.
3: uniform Nag_Boolean Input
On entry: states whether the data points are uniformly spaced.
uniform=Nag_TRUE
The data points are uniformly spaced.
uniform=Nag_FALSE
The data points are not uniformly spaced.
Constraint: if method=Nag_CubicInterp, uniform must be Nag_TRUE.
4: axis[lx] const double Input
On entry: defines the axis. If the data points are uniformly spaced (see argument uniform) axis should contain the start and end of each dimension (x11,x1n1,,xd1,xdnd) .
If the data points are not uniformly spaced, axis should contain all the data ordinates for each dimension (x11,x12,,x1n1,,xd1,xd2,,xdnd).
Constraint: axis must be strictly increasing in each dimension.
5: lx Integer Input
On entry: the dimension of the array axis.
Constraints:
  • if uniform=Nag_TRUE, lx=2d;
  • if uniform=Nag_FALSE, lx=i=1dnarr[i-1].
6: v[dim] const double Input
Note: the dimension, dim, of the array v must be at least i=0 d-1 narr[i].
On entry: holds the values of the data points in such an order that the index of a data value with coordinates (z1,z2,,zd) is
i=1 d zinSin,  
where Si={narr[l-1]:l=1,,i-1} e.g., ((x11,x21,,xd1),(x12,x21,,xd1),,(x1nd,x21,,xd1),(x11,x22,,xd1),(x12,x22,,xd1),,(x1nd,x2nd,,xdnd)).
7: point[d] const double Input
On entry: x, the point at which the data value is to be interpolated.
Constraint: the point must lie inside the limits of the data values in each dimension supplied in axis.
8: method Nag_Interp Input
On entry: the method to be used.
method=Nag_WeightedAverage
Weighted Average.
method=Nag_LinearInterp
Linear Interpolation.
method=Nag_CubicInterp
Cubic Interpolation.
Constraint: method=Nag_WeightedAverage, Nag_LinearInterp or Nag_CubicInterp.
9: k Integer Input
On entry: if method=Nag_WeightedAverage, k controls the number of data points used in the Weighted Average method, with k points used in each dimension, either side of the interpolation point. The total number of data points used for the interpolation will, therefore, be (2k)d.
If methodNag_WeightedAverage, then k is not referenced and need not be set.
Constraint: if method=Nag_WeightedAverage, k1.
10: wf double Input
On entry: the power used for the weighted average such that a high power will cause closer points to be more heavily weighted.
Constraint: if method=Nag_WeightedAverage, 1.0wf15.0.
11: ans double * Output
On exit: holds the result of the interpolation.
12: fail NagError * Input/Output
The NAG error argument (see Section 7 in the Introduction to the NAG Library CL Interface).

6 Error Indicators and Warnings

NE_ALLOC_FAIL
Dynamic memory allocation failed.
See Section 3.1.2 in the Introduction to the NAG Library CL Interface for further information.
NE_BAD_PARAM
On entry, argument value had an illegal value.
NE_INT
Cubic Interpolation method does not have enough data surrounding point; interpolation not possible.
On entry, d=value.
Constraint: d2.
On entry, k=value.
Constraint: if method=Nag_WeightedAverage, k1.
On entry, lx=value, d=value.
Constraint: if uniform=Nag_TRUE, lx=2d.
On entry, lx=value, narr=value.
Constraint: if uniform=Nag_FALSE, lx=narr.
On entry, method=Nag_CubicInterp and uniform=Nag_FALSE.
Constraint: if method=Nag_CubicInterp, uniform must be Nag_TRUE.
NE_INT_2
On entry, narr[value]=value.
Constraint: narr[i-1]2.
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.
See Section 7.5 in the Introduction to the NAG Library CL Interface for further information.
NE_NO_LICENCE
Your licence key may have expired or may not have been installed correctly.
See Section 8 in the Introduction to the NAG Library CL Interface for further information.
NE_NOT_INCREASING
On entry, axis decreases in dimension value.
Constraint: axis definition must be strictly increasing.
NE_REAL
On entry, point[value]=value and data range =[value,value].
Constraint: point must be within the data range.
On entry, wf=value.
Constraint: if method=Nag_WeightedAverage, 1.0wf15.0.
NW_INT
Warning: the size of k has been reduced, due to too few data points around point.

7 Accuracy

For most data the Cubic Interpolation method will provide the best interpolation but it is data dependent. If the data is linear, the Linear Interpolation method will be best. For noisy data the Weighted Average method is advised with wf<2.0 and k>1. This will include more data points and give them a greater influence to the answer.

8 Parallelism and Performance

Background information to multithreading can be found in the Multithreading documentation.
e01zac is not threaded in any implementation.

9 Further Comments

None.

10 Example

This program takes a set of uniform three-dimensional grid data points which come from the function
f(x)= x13- x22+ x3 .  
e01zac then interpolates the data at the point (1.10,0.25,0.75) using all three methods. The answers and the absolute errors are then printed.

10.1 Program Text

Program Text (e01zace.c)

10.2 Program Data

Program Data (e01zace.d)

10.3 Program Results

Program Results (e01zace.r)