This functionality does not run in MATLAB.
interpolate(xList, yList, X, <F>) interpolate(nodes, values, ind, <F>)
interpolate computes an interpolating polynomial through data over a rectangular grid.
The call interpolate(xList, yList, X) with xList = [x1, …, xn] and yList = [y1, …, yn] returns the polynomial of degree less than n in the variable X which interpolates the points (x1, y1), …, (xn, yn).
This call with a 1-dimensional grid xList is equivalent to the corresponding ‘multi-dimensional' call 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 in the grid. P is the polynomial of minimal degree satisfying the interpolation conditions, i.e., degree(P, Xi) < ni.
If only interpolating values at concrete numerical points X1 = v1, …, Xd = vd are required, we recommend not to compute P with symbolic indeterminates ind = [X1, …, Xd] and then evaluate P(v1, …, vd). It is faster to compute this value directly by interpolate with ind = [v1, …, vd]. 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])
poly(- (5563*X^3*Y^4)/23108085 + (16376*X^3*Y^3)/4621617 - (176747*X^3*Y^2)/9243234 + (29440*X^3*Y)/660231 - (40922*X^3)/1100385 + (22397*X^2*Y^4)/10270260 - (16691*X^2*Y^3)/513513 + (367151*X^2*Y^2)/2054052 - (220525*X^2*Y)/513513 + (645283*X^2)/1711710 - (1009*X*Y^4)/161595 + (439024*X*Y^3)/4621617 - (452873*X*Y^2)/840294 + (6293720*X*Y)/4621617 - (1438453*X)/1100385 + (15199*Y^4)/2800980 - (263969*Y^3)/3081078 + (452975*Y^2)/880308 - (4401895*Y)/3081078 + 4199983/2567565, [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 [x1, x2, …] of distinct arithmetical expressions
The values: a list [y1, y2, …] of arithmetical expressions. This list must have the same length as xList.
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 d-dimensional array(1..n,...,1..n[d], [...]) or hfarray(1..n,...,1..n[d], [...]) associating a value with each grid point:
A list of d indeterminates or arithmetical expressions. Indeterminates are either identifiers (of domain type DOM_IDENT) or indexed identifiers (of type "_index").
Either Expr or any field of category Cat::Field
The returned polynomial is of type poly(..., F).
For the default field Expr, all input data may be arbitrary MuPAD® expressions. Standard arithmetic over such expressions is used to compute the polynomial.
For F not being Expr, the grid nodes as well as the entries of values must be elements of F or must be convertible to such elements. Conversion of the input data to elements of F is done automatically.
Interpolating polynomial P of domain type DOM_POLY in the indeterminates specified by ind over the coefficient field F is returned. The elements in ind that 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 ind is returned. This is an element of the field F or an arithmetical expression if F = Expr.
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.