Compute Lagrange polynomial factors

195 Views Asked by At

Consider the Lagrange polynomial of degree $n$ with uniform spacing, which interpolates points $p_0, ..., p_n$ in the following form:

$a_0 + a_1 t + a_2 * t^2 + a_3 t^3 + ... + a_n t^n$

How is it possible to compute the list of successive $a_i$ values?

An example for $n=3$ (cubic) case with $t_0 = 1, t_2 = 2, t_2 = 3, t_3 = 4$:

$-\frac{1}{6} \left(p_0-3 p_1+3 p_2-p_3\right) t^3+\frac{1}{2} \left(3 p_0-8 p_1+7 p_2-2 p_3\right) t^2-\frac{1}{6} \left(26 p_0-57 p_1+42 p_2-11 p_3\right) t+4 p_0-6 p_1+4 p_2-p_3$

so

$a_0 = 4 p_0-6 p_1+4 p_2-p_3$

$a_1 = \frac{1}{6} \left(26 p_0-57 p_1+42 p_2-11 p_3\right)$

$a_2 = \frac{1}{2} \left(3 p_0-8 p_1+7 p_2-2 p_3\right)$

$a_3 = -\frac{1}{6} \left(p_0-3 p_1+3 p_2-p_3\right)$

and with $t_0 = 0, t_1 = 1, t_2 = 2, t_3 = 3$ (which is preferable):

$-\frac{1}{6} \left(p_0-3 p_1+3 p_2-p_3\right) t^3+\frac{1}{2} \left(2 p_0-5 p_1+4 p_2-p_3\right) t^2-\frac{1}{6} \left(11 p_0-18 p_1+9 p_2-2 p_3\right) t+p_0$

so

$t_0 = p_0$

$t_1 = -\frac{1}{6} \left(11 p_0-18 p_1+9 p_2-2 p_3\right)$

$t_2 = \frac{1}{2} \left(2 p_0-5 p_1+4 p_2-p_3\right)$

$t_3 = -\frac{1}{6} \left(p_0-3 p_1+3 p_2-p_3\right)$

1

There are 1 best solutions below

2
On BEST ANSWER

To precompute the coefficients, you solve

$$\begin{bmatrix}1&t_0&t_0^2&\cdots&t_0^{n-1}\\ 1&t_1&t_1^2&\cdots&t_1^{n-1}\\ \vdots&\vdots&\vdots&\ddots&\vdots\\ 1&t_{n-1}&t_{n-1}^2&\cdots&t_{n-1}^{n-1}\\ \end{bmatrix}\begin{bmatrix}a_0\\a_1\\\vdots\\a_{n-1}\end{bmatrix}=\begin{bmatrix}p_0\\p_1\\\vdots\\p_{n-1}\end{bmatrix}.$$

If you want to get the solution for arbitrary $p_k$, simply compute the matrix inverse. You can find a general formula here: https://proofwiki.org/wiki/Inverse_of_Vandermonde%27s_Matrix.


For instance $$\begin{bmatrix}1& 0& 0& 0\\1& 1&1&1\\1&2&4&8\\1&3&9& 27\end{bmatrix}^{-1}=\begin{bmatrix}1& 0& 0& 0\\-11/6& 3& -3/2& 1/3\\1& -5/2& 2& -1/2\\-1/6& 1/2& -1/2& 1/6\end{bmatrix}.$$