Jump to content

Multidimensional interpolation: Difference between revisions

From Wikibase
Say in which order the readings are indexed in the example. AI-assisted (RonzzWikiCowriter) (via update-page on MediaWiki MCP Server)
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)
Line 43: Line 43:
|}
|}


With $m=2$ and $n=4$, the sum has $n^m=16$ terms, one per station, each one station reading times one longitude basis polynomial times one latitude basis polynomial. Writing $x_1$ for longitude and $x_2$ for latitude, and keeping the table's order with the latitude row first, so that $i_2=0$ is the row at $50^\circ$N and $i_1=0$ the column at $0^\circ$E:
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:


$$
$$
f(x_1,x_2)=\sum_{i_1=0}^{3}\sum_{i_2=0}^{3}y_{i_2,i_1}\,L^{(1)}_{i_1}(x_1)\,L^{(2)}_{i_2}(x_2)
f(x_1,x_2)=\sum_{i_1=0}^{3}\sum_{i_2=0}^{3}y_{i_2,i_1}\,L_{i_1}(x_1)\,L_{i_2}(t)
$$
$$


'''A manual evaluation at $1.4^\circ$E, $51.6^\circ$N.''' The longitude nodes are $0,1,2,3$ and the latitude nodes $50,51,52,53$, so evaluating $f$ needs only the basis polynomials at two fixed arguments. For the second longitude node:
'''The basis polynomials.''' The product formula on the nodes $0,1,2,3$ gives four cubics, which serve both variables, in $x_1$ and in $t$:


$$
$$
L^{(1)}_1(1.4)=\frac{(1.4-0)(1.4-2)(1.4-3)}{(1-0)(1-2)(1-3)}=\frac{1.4\cdot(-0.6)\cdot(-1.6)}{1\cdot(-1)\cdot(-2)}=\frac{1.344}{2}=\frac{84}{125}=0.672
L_0(x)=-\frac{(x-1)(x-2)(x-3)}{6}=-\frac{1}{6}x^3+x^2-\frac{11}{6}x+1,\qquad L_1(x)=\frac{x(x-2)(x-3)}{2}=\frac{1}{2}x^3-\frac{5}{2}x^2+3x
$$
$$


and the four longitude weights are
$$
L_2(x)=-\frac{x(x-1)(x-3)}{2}=-\frac{1}{2}x^3+2x^2-\frac{3}{2}x,\qquad L_3(x)=\frac{x(x-1)(x-2)}{6}=\frac{1}{6}x^3-\frac{1}{2}x^2+\frac{1}{3}x
$$
 
'''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:


$$
$$
\left(L^{(1)}_0,\ L^{(1)}_1,\ L^{(1)}_2,\ L^{(1)}_3\right)(1.4)=\tfrac{1}{125}\left(-8,\ 84,\ 56,\ -7\right)
f(x_1,x_2)=Q_0(x_1)L_0(t)+Q_1(x_1)L_1(t)+Q_2(x_1)L_2(t)+Q_3(x_1)L_3(t),\qquad Q_{i_2}(x_1)=\sum_{i_1=0}^{3}y_{i_2,i_1}L_{i_1}(x_1)
$$
$$


They sum to $1$, as they must, since the constant function is reproduced exactly. The latitude weights are the same four numbers in reverse order, $51.6$ lying as far above $51$ as $1.4$ lies below $2$:
so $Q_{i_2}$ is the cubic through the four readings of the parallel at $x_{2,i_2}$. Carrying out the four sums with the cubics above:
 
{| class="wikitable"
|+ The parallel cubics, in expanded form
! parallel !! $Q_{i_2}(x_1)$
|-
! $50^\circ$N
| $-\frac{1}{10}x_1^3+\frac{11}{20}x_1^2+\frac{7}{20}x_1+\frac{114}{5}$
|-
! $51^\circ$N
| $-\frac{3}{20}x_1^3+\frac{3}{4}x_1^2+\frac{1}{5}x_1+\frac{217}{10}$
|-
! $52^\circ$N
| $-\frac{2}{15}x_1^3+\frac{7}{10}x_1^2+\frac{7}{30}x_1+\frac{201}{10}$
|-
! $53^\circ$N
| $-\frac{11}{60}x_1^3+\frac{19}{20}x_1^2-\frac{1}{15}x_1+\frac{92}{5}$
|}
 
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


$$
$$
\left(L^{(2)}_0,\ L^{(2)}_1,\ L^{(2)}_2,\ L^{(2)}_3\right)(51.6)=\tfrac{1}{125}\left(-7,\ 56,\ 84,\ -8\right)
L_1(1.4)=\frac{1.4(1.4-2)(1.4-3)}{2}=\frac{1.4\cdot(-0.6)\cdot(-1.6)}{2}=\frac{1.344}{2}=0.672
$$
$$


Multiplying the readings of each latitude row by the longitude weights gives the value of the interpolant at $1.4^\circ$E on that row:
and the same substitution in the other three gives
 
{| class="wikitable"
|+ 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:
 
$$
Q_0(1.4)=-\tfrac{1}{10}(2.744)+\tfrac{11}{20}(1.96)+\tfrac{7}{20}(1.4)+22.8=-0.2744+1.078+0.49+22.8=24.0936
$$


$$
$$
\tfrac{1}{125}\left(-8\cdot22.8+84\cdot23.6+56\cdot24.9-7\cdot26.1\right)=\tfrac{3011.7}{125}=24.0936
Q_0(1.4)=-0.064\cdot22.8+0.672\cdot23.6+0.448\cdot24.9-0.056\cdot26.1=24.0936
$$
$$
and the basis values are the quicker route for the other three rows:


$$
$$
\tfrac{1}{125}\left(-8\cdot21.7+84\cdot22.5+56\cdot23.9-7\cdot25.0\right)=\tfrac{2879.8}{125}=23.0384
Q_1(1.4)=-0.064\cdot21.7+0.672\cdot22.5+0.448\cdot23.9-0.056\cdot25.0=23.0384
$$
$$


$$
$$
\tfrac{1}{125}\left(-8\cdot20.1+84\cdot20.9+56\cdot22.3-7\cdot23.5\right)=\tfrac{2679.1}{125}=21.4328
Q_2(1.4)=-0.064\cdot20.1+0.672\cdot20.9+0.448\cdot22.3-0.056\cdot23.5=21.4328
$$
$$


$$
$$
\tfrac{1}{125}\left(-8\cdot18.4+84\cdot19.1+56\cdot20.6-7\cdot21.8\right)=\tfrac{2458.2}{125}=19.6656
Q_3(1.4)=-0.064\cdot18.4+0.672\cdot19.1+0.448\cdot20.6-0.056\cdot21.8=19.6656
$$
$$


for the rows at $50$, $51$, $52$, and $53^\circ$N. Multiplying those four results by the latitude weights gives the reading at the query point:
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:


$$
$$
f(1.4,51.6)=\tfrac{1}{125}\left(-7\cdot24.0936+56\cdot23.0384+84\cdot21.4328-8\cdot19.6656\right)=\tfrac{2764.5256}{125}=22.1162
f(1.4,51.6)=24.0936(-0.056)+23.0384(0.448)+21.4328(0.672)+19.6656(-0.064)=22.1162
$$
$$



Revision as of 14:00, 27 October 2026

Languages: English · français · Esperanto

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:

$$ \{(x_{1,i_1},\cdots,x_{m,i_m},y_{i_1,\cdots,i_m})\mid i_1,\cdots,i_m \in [0,n-1],\, i_1,\cdots,i_m \in \mathbb{N}\} $$

then the interpolant is the multivariable Lagrange polynomial

$$ f(x_1,\cdots,x_m)=\sum_{i_1=0}^{n-1}\cdots\sum_{i_m=0}^{n-1}y_{i_1,\cdots,i_m}\prod_{j=1}^{m}L^{(j)}_{i_j}(x_j),\qquad L^{(j)}_{i}(x_j)=\prod_{\substack{k=0\\k\neq i}}^{n-1}\frac{x_j-x_{j,k}}{x_{j,i}-x_{j,k}} $$

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.

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^*$:

$$ y^*_{i_2}=\sum_{i_1=0}^{n-1}L^{(1)}_{i_1}(x_1^*)\,y_{i_1,i_2},\qquad \forall i_2\in [0,n-1], i_2 \in \mathbb{N} $$

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^*$:

$$ f(x_1^*,x_2^*)=\sum_{i_2=0}^{n-1}L^{(2)}_{i_2}(x_2^*)\,y^*_{i_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$:

$$ \sum_{k=0}^{m-1}n^{k}=\frac{n^{m}-1}{n-1} $$

and the passes are exactly the nested form

$$ f(x_1^*,\cdots,x_m^*)=\sum_{i_m=0}^{n-1}L^{(m)}_{i_m}(x_m^*)\sum_{i_{m-1}=0}^{n-1}L^{(m-1)}_{i_{m-1}}(x_{m-1}^*)\cdots\sum_{i_1=0}^{n-1}L^{(1)}_{i_1}(x_1^*)\,y_{i_1,\cdots,i_m} $$

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:

def grid_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)
    for axis in range(len(axes) - 1, -1, -1):        # collapse one variable per pass
        data = np.tensordot(data, lagrange_weights(axes[axis], point[axis]),
                            axes=([axis], [0]))
    return float(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.

References