The
GRID3 function fits a smooth function to a set of 3D scattered nodes (*
x*
_{
i}
, *
y*
_{
i}
, *
z*
_{
i}
) with associated data values (*
f*
_{
i}
). The function can be sampled over a set of user-specified points, or over an arbitrary 3D grid which can then be viewed using the
SLICER procedure.

GRID3 uses the method described in Renka, R. J., "Multivariate Interpolation of Large Sets of Scattered Data," *
ACM Transactions on Mathematical Software*
, Vol. 14, No. 2, June 1988, Pages 139-148, which has been referred to as the Modified Shepard's Method. The function described by this method has the advantages of being equal to the values of *
f*
_{
i}
, at each (*
x*
_{
i}
, *
y*
_{
i}
, *
z*
_{
i}
), and being smooth (having continuous first partial derivatives).

If no optional or keyword parameters are supplied, GRID3 produces a regularly-sampled volume with dimensions of (25, 25, 25), made up of single-precision, floating-point values, enclosing the original data points.

Arrays containing the locations of the data points, and the value of the variable to be interpolated at that point. *
X*
, *
Y*
, *
Z*
, and *
F*
must have the same number of elements (with a minimum of 10 elements per array) and are converted to floating-point if necessary.

Note: For the greatest possible accuracy, the arrays *
X*
, *
Y*
, and *
Z*
should be scaled to fit in the range [0,1].

Optional arrays containing the locations within the volume to be sampled (if the GRID keyword is not set), or the locations along each axis of the sampling grid (if the GRID keyword is set). If these parameters are supplied, the keywords DELTA, NGRID, and START are ignored.

If the keyword GRID is *
not*
set, the result has the same number of elements as *
G*
_{
x}
, *
G*
_{
y}
, and *
G*
_{
z}
. The *
i*
th element of the result contains the value of the interpolate at (*
G*
_{
xi}
, *
G*
_{
yi}
, *
G*
_{
zi}
). The result has the same dimensions as *
G*
_{
x}
.

If the GRID keyword is set, the result of GRID3 is a three-dimensional, single-precision, floating-point array with dimensions of (*
N*
_{
x}
, *
N*
_{
y}
, *
N*
_{
z}
), where *
N*
_{
x}
, *
N*
_{
y}
, and *
N*
_{
z}
are the number of elements in *
G*
_{
x}
, *
G*
_{
y}
, and *
G*
_{
z}
, respectively.

Set this keyword to a three-element vector or a scalar that specifies the grid spacing in the X, Y, and Z dimensions. The default spacing produces NGRID samples within the range of each axis.

The tolerance for detecting an ill-conditioned system of equations. The default value is 0.01, which is appropriate for small ranges of *
X*
, *
Y*
, and *
Z*
. For large ranges of *
X*
, *
Y*
, or *
Z*
, it may be necessary to decrease the value of DTOL. If you receive the error message "GRID3: Ill-conditioned matrix or all nodes co-planar," try decreasing the value of DTOL.

This keyword specifies the interpretation of *
G*
_{
x}
, *
G*
_{
y}
, and *
G*
_{
z}
. The default value for GRID is zero if *
G*
_{
x}
, *
G*
_{
y}
, and *
G*
_{
z}
are supplied, otherwise a regularly-gridded volume is produced.

Produce a set random points within the (0,1) unit cube and simulate a function:

N = 300 *;
Number of irregular samples.*

X = RANDOMU(SEED, N) *;
Generate random values between 0 and 1.*

F = (X-.5)^2 + (Y-.5)^2 + Z *;
The function to simulate.*

Return a cube with 25 equal-interval samples along each axis:

Return a cube with 11 elements along each dimension, which samples each axis at (0, 0.1, ..., 1.0):

Result = GRID3(X, Y, Z, F, START=[0., 0., 0], $

The same result is produced by the statements: