This functionality does not run in MATLAB.
interpolate computes an interpolating polynomial
through data over a rectangular grid.
interpolate(xList, yList, X) with
= [x1, …, xn] and
= [y1, …, yn] returns
the polynomial of degree less than n in
X which interpolates the points (x1, y1),
…, (xn, yn).
This call with a 1-dimensional
xList is equivalent to the corresponding ‘multi-dimensional'
interpolate([xList], array(1..n, [yList]), [X]).
For d-dimensional interpolation, assume that indeterminates ind = [X1, …, Xd] are specified. The interpolating polynomial P = poly(…, [X1, …, Xd], F) satisfies
for all points
the grid. P is
the polynomial of minimal degree satisfying the interpolation conditions,
If only interpolating values at concrete numerical points X1 = v1,
…, Xd = vd are
required, we recommend not to compute P with
ind = [X1,
…, Xd] and
then evaluate P(v1,
It is faster to compute this value directly by
ind = [v1,
Cf. examples Example 1 and Example 3.
We consider a 1-dimensional interpolation problem. To each node xi, a value yi is associated. The interpolation polynomial P with P(xi) = yi is:
xList := [1, 2, 3]: yList := [y1, y2, y3]: P := interpolate(xList, yList, X)
The evaluation of P at the point is given by:
evalp(P, X = 5/2)
This value can also be computed directly without the symbolic polynomial:
interpolate(xList, yList, 5/2)
delete xList, yList, P:
We demonstrate multi-dimensional interpolation. Consider data over the following 2-dimensional 2 ×3 grid:
XList := [1, 2]: YList := [1, 2, 3]: values := array(1..2, 1..3, [[1, 2, 3], [3, 2, 1]]): P := interpolate([XList, YList], values, [X, Y])
Next, interpolation over a 3-dimensional 2 ×3×2 grid is demonstrated:
L1 := [1, 2]: L2 := [1, 2, 3]: L3 := [1, 2]: values := array(1..2, 1..3, 1..2, [[[1, 4], [1, 2], [3, 3]], [[1, 4], [1, 3], [4, 0]]]): interpolate([L1, L2, L3], values, [X, Y, Z])
delete XList, values, P, L1, L2, L3:
We interpolate data over a 2-dimensional grid:
n1 := 4: L1 := [i $ i = 1..n1]: n2 := 5: L2 := [i $ i = 1..n2]: f := (X, Y) -> 1/(1 + X^2 + Y^2): values := array(1..n1, 1..n2, [[f(L1[i], L2[j]) $ j=1..n2] $ i=1..n1]):
First, we compute the symbolic polynomial:
P := interpolate([L1, L2], values, [X, Y])
Fixing the value Y = 2.5, this yields a polynomial in X.
evalp(P, Y = 2.5)
It can also be computed directly by using an evaluation point for the indeterminate Y:
interpolate([L1, L2], values, [X, 2.5])
If all indeterminates are replaced by evaluation points, the corresponding interpolation value is returned:
interpolate([L1, L2], values, [1.2, 2.5])
delete n1, n2, f, values, P:
We demonstrate interpolation over a special coefficient field. Consider the following data over a 2-dimensional 2 ×3 grid:
XList := [3, 4]: YList := [1, 2, 3]: values := array(1..2, 1..3, [[0, 1, 2], [3, 2, 1]]):
With the following call, these data are converted to integers modulo 7. Arithmetic over this field is used:
F := Dom::IntegerMod(7): P := interpolate([XList, YList], values, [X, Y], F)
Evaluation of P at grid points reproduces the associated values converted to the field:
evalp(P, X = XList, Y = YList) = F(values[2, 3])
delete XList, YList, values, F, P:
The nodes: a list
The values: a list
A list [L1, …, Ld] of d lists Li defining a d-dimensional rectangular grid
The lists Li may have different lengths ni = |Li|. The elements of each Li must be distinct.
A list of d indeterminates
or arithmetical expressions. Indeterminates are either identifiers
(of domain type
The returned polynomial is of type
For the default field
Interpolating polynomial P of
the indeterminates specified by
ind over the coefficient
F is returned. The elements in
are not indeterminates but arithmetical expressions are not used as
indeterminates in P,
but enter its coefficients: the polynomial is "evaluated"
at these points. If no element of
ind is an indeterminate,
the value of the polynomial at the point specified by
returned. This is an element of the field
an arithmetical expression if
For a d-dimensional rectangular grid
specified by the lists
with associated values
the interpolating polynomial in the indeterminates X1, …, Xd is given by
with the Lagrange polynomials
associated with the k-th node of the j-th coordinate.