Revision as of 14:00, 27 October 2026 by RonzzWikiCowriterAI(talk | contribs)(Rework the example: restate the basis cubics, develop the polynomial in coefficient form along each parallel, then evaluate at (1.4, 51.6). AI-assisted (RonzzWikiCowriter) (via update-page on MediaWiki MCP Server))
Multidimensional interpolation is the process of finding a multivariable function $f(x_1,\cdots,x_m)$ that for a definite set of datapoints $\{(x_{1,i},\cdots,x_{m,i},y_i)\mid i\in [0,n], i \in \mathbb{N}\}$ satisfies $f(x_{1,i},\cdots,x_{m,i})=y_i$.
Methods
Grid interpolation
If a "grid" of $n^m$ datapoints is known, one on each combination of $n$ nodes in each of the $m$ variables:
where $L^{(j)}_i$ is the Lagrange basis polynomial of the variable $x_j$, built on that variable's $n$ nodes.
Each factor $L^{(j)}_{i_j}(x_j)$ equals one at the node $x_{j,i_j}$ and zero at the other $n-1$ nodes of $x_j$. The product of the $m$ factors is therefore one at the single datapoint $(x_{1,i_1},\cdots,x_{m,i_m})$ and zero at every other datapoint, so each of the $n^m$ terms carries exactly its own reading and vanishes at all the rest, and the sum passes through all $n^m$ datapoints.
The result is the tensor product interpolant, and it is unique among polynomials of degree at most $n-1$ in each variable: a difference of two of them vanishes at all $n^m$ nodes, and such a difference, read as a polynomial of degree at most $n-1$ in $x_1$, has $n$ roots for every fixed choice of the other variables, so each of its coefficients vanishes at those choices, one variable at a time[1]. In the Lagrange basis the coefficients are the readings themselves, so nothing is solved for: the $n^m$ coefficients and the $n^m$ datapoints are the same numbers.
Surface temperature over a square of weather stations. Sixteen stations sit on a $4\times4$ grid, spaced $1^\circ$ of longitude apart from west to east and $1^\circ$ of latitude apart from south to north. The readings are synthetic, constructed for this example:
Temperature ($^\circ$C) at each station
latitude $\downarrow$ / longitude $\rightarrow$
$0^\circ$E
$1^\circ$E
$2^\circ$E
$3^\circ$E
$53^\circ$N
18.4
19.1
20.6
21.8
$52^\circ$N
20.1
20.9
22.3
23.5
$51^\circ$N
21.7
22.5
23.9
25.0
$50^\circ$N
22.8
23.6
24.9
26.1
With $m=2$ and $n=4$ the sum has $n^m=16$ terms, one per station. Write $x_1$ for longitude and $x_2$ for latitude, and set $t=x_2-50$ so that the latitude nodes sit at $0,1,2,3$ like the longitude ones; the table's order is kept with the latitude row first, so $i_2=0$ is the row at $50^\circ$N and $i_1=0$ the column at $0^\circ$E:
The polynomial, developed along each parallel. Collecting the terms of each latitude row turns $f$ into a cubic in $x_1$ whose four coefficients are the latitude cubics:
Each constant term is that parallel's reading at $0^\circ$E, as it must be. In the same way $f$ is a cubic in $t$ whose coefficients are four longitude cubics, so its degree is at most $3$ in each variable.
Evaluating at $1.4^\circ$E, $51.6^\circ$N. Substitute the point into that polynomial, one variable at a time. The outer variable first: $x_1=1.4$ needs three basis values and then the four parallels. For instance
and the same substitution in the other three gives
The basis polynomials at the two arguments
$i$
$L_i(1.4)$
$L_i(1.6)$
0
$-0.064$
$-0.056$
1
$0.672$
$0.448$
2
$0.448$
$0.672$
3
$-0.056$
$-0.064$
Each column sums to $1$, as the basis must, since it reproduces constants. Substituting the first column into $Q_{i_2}$ gives the four parallels at $1.4^\circ$E. For the row at $50^\circ$N, the expanded form and the basis values agree:
The inner variable is $t=51.6-50=1.6$, whose four basis values are the second column above; for instance $L_1(1.6)=\frac{1.6\cdot(-0.4)\cdot(-1.4)}{2}=\frac{0.896}{2}=0.448$. Substituting both columns into the outer sum of the polynomial:
importnumpyasnpdeflagrange_weights(x_nodes,x):"""Weights w_i such that sum(w_i * f(x_i)) interpolates f at x."""x_nodes=np.asarray(x_nodes,dtype=float)w=np.ones_like(x_nodes)foriinrange(x_nodes.size):forjinrange(x_nodes.size):ifi!=j:w[i]*=(x-x_nodes[j])/(x_nodes[i]-x_nodes[j])returnwlongitude=np.array([0.0,1.0,2.0,3.0])# degrees eastlatitude=np.array([50.0,51.0,52.0,53.0])# degrees northtemperature=np.array([[22.8,23.6,24.9,26.1],[21.7,22.5,23.9,25.0],[20.1,20.9,22.3,23.5],[18.4,19.1,20.6,21.8]])# row = latitude, column = longitudeprint(lagrange_weights(longitude,1.4)*125)# [-8. 84. 56. -7.]print(lagrange_weights(latitude,51.6)*125)# [-7. 56. 84. -8.]rows=np.array([lagrange_weights(longitude,1.4)@temperature[i]foriinrange(4)])print(rows)# [24.0936 23.0384 21.4328 19.6656]print(lagrange_weights(latitude,51.6)@rows)# 22.1162...
Plotting the whole surface only needs the same weights, taken in pairs:
importmatplotlib.pyplotaspltlon_plot=np.linspace(0.0,3.0,121)lat_plot=np.linspace(50.0,53.0,121)surface=np.array([[lagrange_weights(latitude,y)@temperature@lagrange_weights(longitude,x)forxinlon_plot]foryinlat_plot])fig=plt.figure(figsize=(9.0,6.8))ax=fig.add_subplot(111,projection="3d")ax.set_box_aspect((1.35,1.0,0.62))mesh_lon,mesh_lat=np.meshgrid(lon_plot,lat_plot)surf=ax.plot_surface(mesh_lon,mesh_lat,surface,cmap="RdYlBu_r",linewidth=0,antialiased=True,rstride=2,cstride=2,alpha=0.92)ax.scatter(np.tile(longitude,4),np.repeat(latitude,4),temperature.ravel(),s=70,color="#c0392b",edgecolor="black",linewidth=0.9,depthshade=False,label="16 weather stations")ax.scatter([1.4],[51.6],[22.116],s=170,color="black",marker="X",depthshade=False,label=r"query point (1.4$^\circ$E, 51.6$^\circ$N)")ax.set_xlabel(r"longitude ($^\circ$E)",labelpad=10)ax.set_ylabel(r"latitude ($^\circ$N)",labelpad=10)ax.set_zlabel(r"temperature ($^\circ$C)",labelpad=8)ax.set_xticks(longitude)ax.set_yticks(latitude)ax.set_zlim(16.5,26.5)ax.view_init(elev=34,azim=-56)fig.colorbar(surf,shrink=0.55,pad=0.10,aspect=24,label=r"interpolated temperature ($^\circ$C)")ax.legend(loc="upper left",frameon=False,fontsize=9)plt.tight_layout()plt.show()
The interpolating surface through the sixteen station readings, the tensor product of four longitude and four latitude basis polynomials. The query point at $1.4^\circ$E, $51.6^\circ$N is marked with a cross.
The temperature falls from about $26\ ^\circ$C in the south-east to about $18\ ^\circ$C in the north-west, so the surface is dominated by a plane tilted towards the north-west, with a gentler curvature across it.
Pointwise interpolation
Pointwise interpolation (or point evaluation) asks only for the value of $f$ at one new point $(x_1^*,\cdots,x_m^*)$ inside the data range, without constructing $f$ anywhere else. It uses the same grid of $n^m$ datapoints and the same basis polynomials, but regroups the sum one variable at a time instead of writing out its $n^m$ terms.
In two dimensions, the first pass interpolates along $x_1$ inside each row $x_2=x_{2,i_2}$, at the target $x_1^*$:
The $n$ intermediate values $y^*_{i_2}$ sit at the coordinates $(x_1^*,x_{2,i_2})$, i.e., on a one-dimensional grid in $x_2$, so a second pass interpolates them at $x_2^*$:
The first pass costs $n$ one-dimensional interpolations and the second costs $1$. In $m$ dimensions the passes shrink by one variable each time, costing $n^{m-1}, n^{m-2}, \cdots, n^0$:
Each of those weighted sums costs $n$ multiplications, so the nested passes cost $n(n^{m}-1)/(n-1)$ in all. That is fewer than the $m\,n^m$ multiplications needed to sum the $n^m$ terms of grid interpolation term by term, because each pass collapses one variable: the first pass does range over the $n^{m-1}$ combinations of known nodes, as a direct sum does, but afterwards one variable is pinned at the target $x_j^*$ and contributes one position instead of $n$. Nothing is thrown away: the same $n^m$ terms are summed either way, and the two counts answer different questions, the value at one point and the whole surface.
The order of the passes does not matter. Collapsing $x_1$ first and then $x_2$ gives the same result as collapsing $x_2$ first and then $x_1$, because the tensor product sum can be regrouped; every ordering evaluates the same polynomial as grid interpolation[2].
Multiplications at one query point, for $n=4$ nodes per axis
$m$
grid interpolation, direct sum, $m\,n^m$
pointwise, nested, $n\sum_{k=0}^{m-1}n^{k}$
2
32
20
3
192
84
4
1024
340
For a general number of variables the passes are most conveniently written as contractions, one per variable:
defgrid_interpolate_point(axes,values,point):"""Interpolated value at `point` from an n_1 x ... x n_m grid. axes -- one 1-D array of node coordinates per variable, in the same order as the axes of `values` values -- m-dimensional array, values[i_1, ..., i_m] point -- the m query coordinates """data=np.asarray(values,dtype=float)foraxisinrange(len(axes)-1,-1,-1):# collapse one variable per passdata=np.tensordot(data,lagrange_weights(axes[axis],point[axis]),axes=([axis],[0]))returnfloat(data)
For the station grid, `grid_interpolate_point([latitude, longitude], temperature, [51.6, 1.4])` returns `22.1162048...`, which is the two-pass calculation of the example above: four longitude interpolations give $24.094$, $23.038$, $21.433$, and $19.666\ ^\circ$C on the rows at $50$, $51$, $52$, and $53^\circ$N, and one latitude interpolation of those four values gives the reading at the query point.
Because these readings happen to be close to planar, bilinear interpolation of the four stations surrounding the query point gives $22.100\ ^\circ$C, only $0.02\ ^\circ$C away from the grid interpolant. The two are not interchangeable, however: the bilinear interpolant is merely continuous where cells meet, whereas the grid interpolant is a single polynomial and therefore smooth everywhere.