# Numerical Analysis/Lagrange example

We'll find the interpolating polynomial passing through the points ${\displaystyle (1,-6)}$, ${\displaystyle (2,2)}$, ${\displaystyle (4,12)}$, using the Lagrange method.

We first use the formula to write the following:

${\displaystyle p(x)=-6{\frac {(x-2)}{(1-2)}}{\frac {(x-4)}{(1-4)}}+2{\frac {(x-1)}{(2-1)}}{\frac {(x-4)}{(2-4)}}+12{\frac {(x-1)}{(4-1)}}{\frac {(x-2)}{(4-2)}}}$

After some simplification, we get:

${\displaystyle p(x)=-2(x-2)(x-4)-1(x-1)(x-4)+2(x-1)(x-2)}$

${\displaystyle p(x)=-2(x^{2}-6x+8)-1(x^{2}-5x+4)+2(x^{2}-3x+2)}$

${\displaystyle p(x)=-x^{2}+11x-16}$.

Now we'll add a point to our data set, and find a new interpolating polynomial. Let us add the point ${\displaystyle (3,-10)}$ to our set. Starting over with the Lagrange formula, we write:

${\displaystyle p(x)=-6{\frac {(x-2)}{(1-2)}}{\frac {(x-4)}{(1-4)}}{\frac {(x-3)}{(1-3)}}+2{\frac {(x-1)}{(2-1)}}{\frac {(x-4)}{(2-4)}}{\frac {(x-3)}{(2-3)}}+12{\frac {(x-1)}{(4-1)}}{\frac {(x-2)}{(4-2)}}{\frac {(x-3)}{(4-3)}}-10{\frac {(x-1)}{(3-1)}}{\frac {(x-2)}{(3-2)}}{\frac {(x-4)}{(3-4)}}}$

Simplifying, we get:

${\displaystyle p(x)=(x-2)(x-4)(x-3)+(x-1)(x-4)(x-3)+2(x-1)(x-2)(x-3)+5(x-1)(x-2)(x-4)}$

${\displaystyle p(x)=(x^{3}-9x^{2}+26x-24)+(x^{3}-8x^{2}+19x-12)+2(x^{3}-6x^{2}+11x-6)+5(x^{3}-7x^{2}+14x-8)}$

And our polynomial is:

${\displaystyle p(x)=9x^{3}-64x^{2}+137x-88}$.