n-dimensional data interpolation (table lookup) - Maple Help

Online Help

All Products    Maple    MapleSim

Home : Support : Online Help : Mathematics : Numerical Computations : Interpolation and Curve Fitting : CurveFitting Package : CurveFitting/ArrayInterpolation

CurveFitting[ArrayInterpolation] - n-dimensional data interpolation (table lookup)

Calling Sequence

ArrayInterpolation(xdata, ydata, xvalues, options)

ArrayInterpolation(xydata, xvalues, options)




a list, Array, Vector, or Matrix containing the independent coordinate(s) of each of the data points, given in one of several possible forms



a list, Array, or Vector containing the dependent coordinate of each of the data points



alternate input; a list, Array, or Matrix containing both the dependent and independent coordinates of each of the data points



a numeric value, list, Vector, or Array containing the independent coordinate(s) of one or more points whose dependent coordinate will be approximated using interpolation



(optional) equation(s) of the form keyword = value, where keyword is one of method, degree, endpoints, knots, uniform, verify, extrapolate, or container.



The ArrayInterpolation command takes a finite set of distinct data points given by xdata and ydata (or xydata), and interpolates to approximate the y-values corresponding to the points given in xvalues.  It considers an interpolant function f such that fx=y for all respective pairs x,y in xdata and ydata (or xydata). Such a function can be constructed using one of various methods (see below).  It then computes and returns fxi for all xi in xvalues.


The focus of the ArrayInterpolation command is the performance of quick and efficient data resampling and table lookup.  To actually compute and return interpolants, functions such as CurveFitting[Spline] and CurveFitting[RationalInterpolation] can be used instead.


The ArrayInterpolation function can interpolate numeric data in n dimensions, where n is any positive integer.


The list of independent coordinates of the data points, given in xdata, can be input in a number of different ways.  xdata can be:


(preferred if n=1) a Vector, list, or 1-dimensional Array of strictly increasing x-coordinates. The dataset will then have size a1, where a1 is the length of xdata.


(preferred if 1<n) a list of n Vectors, lists, or 1-dimensional Arrays, one for each dimension of the data.  The jth Vector, list, or Array in the input must contain, in increasing order, all of the possible jth coordinates of the data points.  In this case, the block of data points will be assumed to lie on an a1 by a2 by ... by an grid, where aj is the length of the jth Vector or Array in the input.  The pth coordinate of the data point at index &lsqb;j1, j2, ..., jn&rsqb; (where 1jiai) will be equal to the apth element of the pth Array in the input.


an Array of size a1 by a2 by ... by an by n, giving the independent coordinate(s) of each of a1 by a2 by ... by an data points as an ordered n-tuple. These coordinates must form a proper "grid" of values, and must be sorted in strictly increasing order along each dimension.  More formally,xdata&lsqb;j1, j2, ..., jn, p&rsqb; - xdata&lsqb;k1, k2, ..., kn, p&rsqb; must be zero if jp&equals;kp, and must be positive if kp<jp.


a list of n Arrays of size a1 by a2 by ... by an, where the jth array contains the jth independent coordinate of each of the a1 by a2 by ... by an data points.  The coordinates must form a proper "grid" of values, and must be sorted in strictly increasing order along each dimension.  More formally,opp&comma;xdata&lsqb;j1, j2, ..., jn] - opp&comma;xdata&lsqb;k1, k2, ..., kn&rsqb; must be zero if jp&equals;kp, and must be positive if kp<jp.


The preferred methods minimize memory usage and execution time by avoiding unnecessary storage and verification of redundant data.  In all cases, xdata must contain real values of type numeric.


The list of dependent coordinates of the data points, given in ydata, must be input as an Array (or a Matrix, Vector, or list for appropriate values of n) of size a1 by a2 by ... by an, so that the value of ydata&lsqb;j1, j2, ..., jn&rsqb; corresponds to the element in xdata of index&lsqb;j1, j2, ..., jn&rsqb;. Values in ydata must be real numbers of type numeric.


As an alternate form of input, a single structure xydata containing all coordinates of the data points can be entered.  It can be formatted in one of the following ways:


an Array or Matrix of size a1 by a2 by ... by an by (n&plus;1), giving the independent and dependent coordinate(s) of each of a1 by a2 by ... by an data points as an ordered (n&plus;1)-tuple.  The first n elements in each (n&plus;1)-tuple represent the independent coordinates of each point, and must adhere to the same restrictions as above (a proper "grid" must be formed, and the independent coordinates must be sorted in strictly increasing order along each dimension).  The n&plus;1st coordinate in each (n&plus;1)-tuple then represents the dependent coordinate of the respective data point.


a list of n&plus;1 Arrays, Vectors, Matrices, or lists of size a1 by a2 by ... by an, where the jth array contains the jth independent coordinate of each of the a1 by a2 by ... by an data points for 1jn, and the n&plus;1st Array contains the dependent coordinates of each point.  As above, the independent coordinates must adhere to certain restrictions (a proper "grid" must be formed, and the independent coordinates must be sorted in strictly increasing order along each dimension).


For multidimensional data, these methods are not recommended, since space is wasted storing the full grid of independent coordinates instead of a list of all the possible coordinates in each dimension. In both cases, the coordinates must be real values of type numeric.


The list of values to interpolate at, given in xvalues, may be input in one of the following formats:


for one-dimensional data, a single numeric value, or a Vector, list, or 1-dimensional Array of numeric values can be input.  The output will be returned in a format matching the format of the input.


for multidimensional data, an Array or Matrix of size u1 by u2 by ... by uk by n of numeric values can be input.  It must contain the n coordinates of each of u1 by u2 by ... by uk values to interpolate at, with the value of xvalues&lsqb;j1, j2, ..., jk, p&rsqb; giving the pth coordinate of the respective point.  The output will be returned in an array of size u1 by u2 by ... by uk containing the interpolated results.


alternatively, a list of n Vectors, lists, or 1-dimensional Arrays can be input. The jth Vector, list, or Array in the input will be assumed to contain all of the possible jth coordinates of the values to interpolate at.  In this case, interpolation will be performed on an a1 by a2 by ... by an block of points, where aj is the length of the jth Vector or Array in the input.  The output will then be returned in a Vector, Matrix, list, or Array of size a1 by a2 by ... by an.


If any of the data points in xvalues lie outside the rectangular bounding box specified by the input, then extrapolation will be performed to approximate their corresponding y-values.  The method by which extrapolation is performed can be controlled by using option extrapolate; see below.


This routine has separate numeric methods for handling hardware and software floats.  The decision about which routine to use can be controlled by setting the UseHardwareFloats environment variable.  If UseHardwareFloats remains unset, then hardware floats are used if and only if Digits <= evalhf(Digits), in which case all software floats in the input will be converted to hardware floats.


Only computations involving numeric floating point data are supported by this routine. If the input does not contain floating point data, an error will be thrown.


For optimal performance, all rtables in the input should be Fortran order with rectangular storage (the default). Otherwise, a conversion will take place.  All rtables in the output will be Fortran order rtables with rectangular storage.


This function is part of the CurveFitting package, so it can be used in the short form ArrayInterpolation(..) only after executing the command with(CurveFitting).  However, it can always be accessed through the long form of the command by using CurveFitting[Interpolation](..).




An introductory example.  Suppose a signal is sampled several times over a given interval of time:




ArrayInterpolation to resample the data at a higher sampling frequency:




Use a cubic spline to achieve a smoother, more realistic resampling of the data:



Try again, using a spline that assumes the data is sampled from a periodic waveform:



A 2-dimensional example: a tiny grayscale image stored in a Matrix:




Upsample it to a larger image using bilinear interpolation:




Try again, using bicubic interpolation instead for a smoother fit:



A non-uniform multidimensional example.  Create some 3-D mesh structures to pass through a given set of points defined by a mathematical function:



Define a non-uniform grid of points, and sample f over them:




Plot the data so far:


Create a finer mesh to interpolate over:




Linear interpolation produces a quick approximation to f:



Nearest-neighbor interpolation can also be used for quick lookup purposes:



Spline interpolation produces a smoother approximation to the original function f:



Increasing the degree of the spline approximation can increase the smoothness of the result, but results in a longer computation time, greater numerical instability, and can cause large oscillations around the edges of a data set:



Finally, a large example to illustrate a few tips for increasing the speed of computations:







On such a large 1-dimensional example, a significant portion of the execution time is spent verifying the integrity of the input data.  Disabling this verification will produce a significant speedup in the execution time of the routine, but will produce incorrect results if the input is not correctly formatted or sorted:




Asserting that the data is uniform allows a faster lookup method to be used:




Cubic interpolation takes longer than the default, linear method:




See Also

CurveFitting, CurveFitting[PolynomialInterpolation], CurveFitting[RationalInterpolation], CurveFitting[Spline], CurveFitting[SplineConditions], CurveFitting[ThieleInterpolation]

Download Help Document

Was this information helpful?

Please add your Comment (Optional)
E-mail Address (Optional)
What is ? This question helps us to combat spam