perform nearest neighbor interpolation
perform lowest neighbor interpolation
perform highest neighbor interpolation
perform linear interpolation
perform cubic interpolation
perform spline interpolation
The Interpolating Functions
f := NearestNeighborInterpolation(xdata, ydata, options)
f := NearestNeighborInterpolation(xydata, options)
f := LowestNeighborInterpolation(xdata, ydata, options)
f := LowestNeighborInterpolation(xydata, options)
f := HighestNeighborInterpolation(xdata, ydata, options)
f := HighestNeighborInterpolation(xydata, options)
f := LinearInterpolation(xdata, ydata, options)
f := LinearInterpolation(xydata, options)
f := CubicInterpolation(xdata, ydata, options)
f := CubicInterpolation(xydata, options)
f := SplineInterpolation(xdata, ydata, options)
f := SplineInterpolation(xydata, options)
f(x1, x2, ..., xn, options)
a list, Array, DataFrame, DataSeries, Vector, or Matrix containing the independent coordinate(s) of each of the data points, given in one of several possible forms
a list, Array, DataSeries, or Vector containing the dependent coordinate of each of the data points
alternate input; a list, Array, DataFrame, 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
x1, x2, ..., xn
numeric values; independent coordinate(s) of one point 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 NearestNeighborInterpolation, LowestNeighborInterpolation, HighestNeighborInterpolation, LinearInterpolation, CubicInterpolation, and SplineInterpolation commands take a finite set of distinct data points given by xdata and ydata (or xydata), and return an object. This object can interpolate to approximate the y-values corresponding to the points given in xvalues, or in x1, x2, ..., xn. It considers an interpolant function f such that f⁡x=y for all respective pairsx,y in xdata and ydata (or xydata). Such a function can be constructed using one of various methods; the commands differ in the method used.
The commands described in this help page use the ArrayInterpolation command from the CurveFitting package. If you know all xvalues at which you want to evaluate the interpolant beforehand, you may get slightly better performance calling that command directly. Conversely, the commands on this help page provide better performance if you want to iteratively evaluate the interpolant at various points one by one. Furthermore, to actually compute and return interpolants, functions such as CurveFitting[Spline] and CurveFitting[RationalInterpolation] can be used instead.
The commands described on this help page can interpolate numeric data in n dimensions, where n is any positive integer. For n>1, the independent data points must be in grid form. For independent data points that are not in grid form, you can use CurveFitting[Lowess], Interpolation[NaturalNeighborInterpolation], Interpolation[LinearTriangularInterpolation], Interpolation[RadialBasisFunctionInterpolation], Interpolation[InverseDistanceWeightedInterpolation], or Interpolation[Kriging].
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, DataSeries, list, or one-dimensional Array of strictly increasing x-coordinates. The data set will then have size a1, where a1 is the length of xdata.
(preferred if 1<n) a list of n Vectors, lists, or one-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 [j1, j2, ..., jn] (where 1≤ji≤ai) 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[j1, j2, ..., jn, p] - xdata[k1, k2, ..., kn, p] must be zero if jp=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,xdata[j1, j2, ..., jn] - opp,xdata[k1, k2, ..., kn] must be zero if jp=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 during the definition of f; there is no difference once f has been defined. 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[j1, j2, ..., jn] corresponds to the element in xdata of index [j1, j2, ..., jn]. Values in ydata must be real numbers of type extended_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, DataFrame, or Matrix of size a1 by a2 by ... by an by (n+1), giving the independent and dependent coordinate(s) of each of a1 by a2 by ... by an data points as an ordered (n+1)-tuple. The first n elements in each (n+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+1st coordinate in each (n+1)-tuple then represents the dependent coordinate of the respective data point.
a list of n+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 1≤j≤n, and the n+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.
There are two ways to use the object f, created by these calling sequences:
You can evaluate f at a single point x1, x2, ..., xn, by supplying these values as arguments.
You can evaluate f at multiple points at once; how this works depends on whether n=1 or 1<n:
For one-dimensional data, a Vector, list, or one-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[j1, j2, ..., jk, p] 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 one-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 command 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. If UseHardwareFloats or Digits are modified in between defining f and using it, the accuracy and performance may be worse than if you set the desired setting at the start.
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 Interpolation package, so it can be used in the short form LinearInterpolation(..) etc. only after executing the command with(Interpolation). However, it can always be accessed through the long form of the command by using Interpolation[LinearInterpolation](..).
This section describes the way in which f interpolates the given data points for each of the different commands possibly used to define f. They correspond to different method options for the CurveFitting[ArrayInterpolation] command.
NearestNeighborInterpolation (corresponds to method = nearest): Perform nearest neighbor interpolation. Given a point u, f⁡u is defined to be y, wherex,y is the data point such that the Euclidean distance x−u is minimized.
LowestNeighborInterpolation (corresponds to method = lowest): Perform lowest neighbor interpolation. Given a point u in xvalues, f⁡u is defined to be y, wherex,y is the data point such that u−x is non-negative in all coordinates, but the Euclidean distance x−u is minimized.
HighestNeighborInterpolation (corresponds to method = highest): Perform highest neighbor interpolation. Given a point u in xvalues, f⁡u is defined to be y, wherex,y is the data point such that x−u is non-negative in all coordinates, but the Euclidean distance x−u is minimized.
LinearInterpolation (corresponds to method = linear): Perform n-dimensional linear interpolation (lerping). In the one-dimensional case, f is a piecewise-linear function passing through each data pointx,y in the input. In the multidimensional case, f is the tensor product of n such piecewise linear functions, one for each dimension. f⁡u is computed by performing linear interpolation along the first dimension, then along the second dimension, and so on.
CubicInterpolation (corresponds to method = cubic): Perform piecewise cubic Hermite interpolation. In the one-dimensional case, f is a piecewise-cubic function passing through each data pointx,y in the input. In this case, f⁡u = fi⁡u if u lies in the interval xi,xi+1, where each fi is a cubic polynomial such that fi⁡xi=yi and fi⁡xi+1=yi+1 for all data points xi,yi in the input (where i ranges from 0 to k). The coefficients of the functions fi are determined locally by assigning slopes si to each data point xi and solving for the unique cubic function fi⁡x determined by the additional constraints that fi'xi=siandfi'xi+1=si+1. This forces f to be continuously differentiable (C1). The si themselves are computed using Bessel's method: si is the slope at xi of the parabola passing through xi−1,yi−1, xi,yi, and xi+1,yi+1. In the multidimensional case, f is the tensor product of n such cubic interpolation functions, one for each dimension.
SplineInterpolation (corresponds to method = spline): Perform spline interpolation. By default, natural cubic spline interpolation is used. In the one-dimensional case, f is a piecewise-cubic function passing through each data pointx,y in the input. In this case, f⁡u = fi⁡u if u lies in the interval xi,xi+1, where each fi is a cubic polynomial such that fi⁡xi=yi and fi⁡xi+1=yi+1 for all data points xi,yi in the input (where i ranges from 0 to k). The coefficients of the functions fi are selected such that f is twice continuously differentiable (C2), that is, fi'xi+1=fi+1'xi+1and fi''xi+1=fi+1''xi+1. In addition, the "natural" condition of the spline specifies that f''x0=0 and f''xk=0. In the multidimensional case, f is the tensor product of n such spline functions, one for each dimension. Using SplineInterpolation will produce a smoother interpolant than CubicInterpolation (C2 instead of C1), but is more expensive to set up and more prone to numerical instability because each segment of the spline is determined globally by the positions of all other points in the data set.
Options can be given either during construction of f, or while calling f. An option specified while calling f overrides one specified during construction of f.
If the option extrapolate=e is given, where e is of type extended_numeric or truefalse, then one of the following possible extrapolation methods will be used to compute f⁡x if x lies outside the bounding box specified by the input:
extrapolate = true: Perform extrapolation using the closest valid branch of the interpolating function. In the case of LowestNeighborInterpolation and HighestNeighborInterpolation, this is not be defined for some points, in which case undefined will be returned.
extrapolate = false: Do not extrapolate. An error will be thrown if any point in xvalues lies outside the bounding box specified by the input.
extrapolate = e, where e is of type extended_numeric : Define f⁡x to be e if x lies outside the bounding box specified by the input. e is commonly zero or undefined.
extrapolate=true is used by default.
If the option method=m is given, then it overrides the interpolation method specified by the procedure name. For example, f≔LinearInterpolation⁡xdata,ydata,method=cubic will return a cubic interpolation object, and f⁡xvalues,method=spline will perform spline interpolation regardless of how f was constructed.
If the options degree=d and endpoints=e are given, where d is a positive integer and e is one of natural, notaknot, or periodic, then spline interpolation will be performed using the provided degree and endpoint conditions. See Spline Continuity and End Conditions for details. These options only affect the result if SplineInterpolation is used; they are ignored otherwise. In the multidimensional case, the same degree and endpoint conditions are used for the splines generated in each dimension. The defaults are degree=3 and endpoints=natural, in which case natural cubic spline interpolation will be performed.
If splines of an even degree are being used, the option knots=data forces the use of a spline function where the spline knots are positioned on the nodes. See Spline Continuity and End Conditions for details. The default method, knots=default, defines the spline knots at the midpoints of the nodes when even degree splines are used. This option only affects SplineInterpolation calls; it is ignored for other objects.
When f is evaluated at a single point by supplying the coordinates directly, without a list or other container, Maple copies the values into a buffer that is reused between invocations. For the other calling sequence, where you supply a container with potentially multiple points, you can achieve similar behavior with the container option.
If the option container=c is given, where c is an appropriately sized rtable, then the computation is performed in-place and the result is returned in c. c must be of the correct size and datatype to match the output of the routine. With this option, no additional memory is allocated to store the result; this is a programmer-level feature that can be used to reduce memory usage and decrease the time spent by Maple's garbage collector. The default is container=false, in which case Maple creates and returns a new rtable containing the result.
During construction of f, by default, Maple will sort the coordinates in xdata in each dimension, if they are not sorted already (and permute the entries in ydata accordingly). The data must be sorted for CurveFitting[ArrayInterpolation] to do its work. If you know that your data are sorted already, you can supply the verify = false option, which will disable this process; Maple will assume that the data are sorted.
During the call to f, by default, Maple will pass the option verify = false to the CurveFitting[ArrayInterpolation] command, because the sortedness of the data has already been verified. You can override this by passing verify = true, or just verify, to f.
If the option uniform=true is given, then Maple assumes that the data points are sampled over a grid of uniformly spaced points in each dimension. In other words, if ai,j is the jth possible coordinate in the ith dimension, then di=ai,j−ai,j−1 is assumed to be constant over all possible j, given any fixed value of i. This gives a considerable speedup when the input contains uniform data, since it allows Maple to use a fast lookup algorithm when evaluating the interpolant at the specified points. Otherwise, Maple uses a slower but more general binary search algorithm to perform interpolation. Using the uniform=true option with non-uniform data may produce incorrect results.
An introductory example. Suppose a signal is sampled several times over a given interval of time:
To interpolate the data:
f≔a linear interpolation objectwith 11 points in 1-D