Lagrange's method

We are taking:

$$$ P_ n(x)=\sum_{k=0}^{n}f_k\cdot l_k(x)$$$

where $$$l_k(x)=\dfrac{\prod_{i\neq k}(x-x_i)}{\prod_{i\neq k}(x_k-x_i)}=$$$ $$$=\dfrac{(x-x_0)\cdot(x-x_1)\cdots \widehat{(x-x_k)} \cdots (x-x_n)}{(x_k-x_0)\cdot(x_k-x_1)\cdots \widehat{(x_k-x_k)} \cdots (x_k-x_n)}$$$

where the hat indicates that this term does not appear in the product.

This is, in the numerator we multiply all the polynomials of degree $$1$$ except the $$k$$-th and then we divide by the product of all the differences except the $$k$$-th. In fact, if we evaluate the polynomial at some of the $$x_k$$, we get the value $$f_k$$.

Computed this way, this polynomial is called Lagrange polynomial.

Let's see an example. Let's consider the following table of values:

$$x_k$$ $$1$$ $$2$$ $$4$$ $$5$$
$$f_k$$ $$0$$ $$2$$ $$12$$ $$21$$

and we want to calculate the value $$f(3)$$ by interpolation. We have $$n +1 = 4$$ points, therefore $$n = 3$$, the interpolation will be cubic. The polynomial is written:

$$P_3(x)=f_0\cdot l_0(x)+f_1\cdot l_1(x)+f_2\cdot l_2(x)+f_3\cdot l_3(x)=$$

$$=2\cdot l_1(x)+12\cdot l_2(x)+21\cdot l_3(x)$$

We have to calculate now the associated Lagrange polynomials

$$$ \begin{array}{rl} l_0(x)=& \dfrac{(x-x_1)\cdot(x-x_2) \cdot (x-x_3)} {(x_0-x_1)\cdot(x_0-x_2)\cdot (x_0-x_3)} \\ =&\dfrac{(x-2)\cdot(x-4) \cdot (x-5)}{(1-2)\cdot(1-4)\cdot (1-5)}=\dfrac{-1}{12} (-40+38x-11x^2+x^3)\\ l_1(x)=& \dfrac{(x-x_0)\cdot(x-x_2) \cdot (x-x_3)} {(x_1-x_0)\cdot(x_1-x_2)\cdot (x_1-x_3)} \\ =&\dfrac{(x-1)\cdot(x-4) \cdot (x-5)}{(2-1)\cdot(2-4)\cdot (2-5)}=\dfrac{1}{6} (-20+29x-10x^2+x^3)\\ l_2(x)=& \dfrac{(x-x_0)\cdot(x-x_1) \cdot (x-x_3)} {(x_2-x_0)\cdot(x_2-x_1)\cdot (x_2-x_3)} \\ =&\dfrac{(x-1)\cdot(x-2) \cdot (x-5)}{(4-1)\cdot(4-2)\cdot (4-5)}=\dfrac{-1}{6} (-10+17x-8x^2+x^3)\\ l_3(x)=& \dfrac{(x-x_0)\cdot(x-x_1) \cdot (x-x_2)} {(x_3-x_0)\cdot(x_3-x_1)\cdot (x_3-x_2)} \\ =&\dfrac{(x-1)\cdot(x-2) \cdot (x-4)}{(5-1)\cdot(5-2)\cdot (5-4)}=\dfrac{1}{12} (-8+14x-7x^2+x^3) \end{array} $$$

So the interpolating polynomial is:

$$ P_3(x)=2\cdot l_1(x)+12\cdot l_2(x)+21\cdot l_3(x)= \dfrac{1}{12} (-8+2x+5x^2+x^3)$$

Thus $$f(3)=\dfrac{35}{6}=5.8333\dots$$