Sometimes we need to compute the value of a function at several points but
The interpolation technique may be used to solve these problems. In interpolation, we use the data (value, derivative) of a function at some points to build a new approximate function. These new approximate functions are, for example, polynomials and trigonometric functions.
We will study:
In this type of interpolation we have as data:
And we are searching for a polynomial that goes through all these points. This can be all the information we have about $f$ and there is not necessarily an analytic expression of $f.$
For example, for the points
we are searching for a polynomial that goes through all these points
In the example of the previous graph, since we have $5$ points we can generate $5$ equations and we need $ 5 $ unknowns that will be the coefficients of the polynomial. Thus:
$$P_4(x)=a_0+a_1x+a_2x^2+a_3x^3+a_4x^4$$that is, $a_0,$ $a_1,$ $a_2,$ $a_3$ and $a_4$ are the $5$ unknowns and the polynomial is of degree $4$. In general, for the points $(x_0,y_0),(x_1,y_1),\ldots,(x_n,y_n)$ the interpolating polynomial will be of degree $\leq n$.
The equations are
$$ \begin{array}{lll} P_{4}(x_{0})=y_{0} & \quad & a_{0}+a_{1}x_{0}+a_{2}x_{0}^{2}+a_{3}x_{0}^{3}+a_{4}x_{0}^{4}=y_{0}\\ P_{4}(x_{1})=y_{1} & \quad & a_{0}+a_{1}x_{1}+a_{2}x_{1}^{2}+a_{3}x_{1}^{3}+a_{4}x_{1}^{4}=y_{1}\\ P_{4}(x_{2})=y_{2} & \quad & a_{0}+a_{1}x_{2}+a_{2}x_{2}^{2}+a_{3}x_{2}^{3}+a_{4}x_{2}^{4}=y_{2}\\ P_{4}(x_{3})=y_{3} & \quad & a_{0}+a_{1}x_{3}+a_{2}x_{3}^{2}+a_{3}x_{3}^{3}+a_{4}x_{3}^{4}=y_{3}\\ P_{4}(x_{4})=y_{4} & \quad & a_{0}+a_{1}x_{4}+a_{2}x_{4}^{2}+a_{3}x_{4}^{3}+a_{4}x_{4}^{4}=y_{4} \end{array} $$And the linear system is
$$ \left(\begin{array}{ccccc} 1 & x_{0} & x_{0}^{2} & x_{0}^{3} & x_{0}^{4}\\ 1 & x_{1} & x_{1}^{2} & x_{1}^{3} & x_{1}^{4}\\ 1 & x_{2} & x_{2}^{2} & x_{2}^{3} & x_{2}^{4}\\ 1 & x_{3} & x_{3}^{2} & x_{3}^{3} & x_{3}^{4}\\ 1 & x_{4} & x_{4}^{2} & x_{4}^{3} & x_{4}^{4} \end{array}\right)\left(\begin{array}{c} a_{0}\\ a_{1}\\ a_{2}\\ a_{3}\\ a_{4} \end{array}\right)=\left(\begin{array}{c} y_{0}\\ y_{1}\\ y_{2}\\ y_{3}\\ y_{4} \end{array}\right) $$The coefficient matrix of the system is Vandermonde matrix and its determinant is
that is
which is nonzero if no two $x_i$ are the same. And in this case, the system solution exists and is unique.
In the previous example $(x_k,y_k),$ and $y_k = f(x_k)$ are
And the system is
$$ \left(\begin{array}{ccccc} 1 & x_{0} & x_{0}^{2} & x_{0}^{3} & x_{0}^{4}\\ 1 & x_{1} & x_{1}^{2} & x_{1}^{3} & x_{1}^{4}\\ 1 & x_{2} & x_{2}^{2} & x_{2}^{3} & x_{2}^{4}\\ 1 & x_{3} & x_{3}^{2} & x_{3}^{3} & x_{3}^{4}\\ 1 & x_{4} & x_{4}^{2} & x_{4}^{3} & x_{4}^{4} \end{array}\right)\left(\begin{array}{c} a_{0}\\ a_{1}\\ a_{2}\\ a_{3}\\ a_{4} \end{array}\right)=\left(\begin{array}{c} y_{0}\\ y_{1}\\ y_{2}\\ y_{3}\\ y_{4} \end{array}\right) $$As there are 5 different nodes the determinant of the coefficient matrix is nonzero.
And, solving the system, the Lagrange interpolating polynomial is
One way to obtain the Lagrange interpolating polynomial is to solve the above system. But this system is ill-conditioned (small errors in the data can produce large errors in the results) and the computation is comparatively expensive.
We are going to see two alternative ways to compute the Lagrange interpolation polynomial:
For the nodes $x_{0}=-1,$ $x_{1}=1,$ $x_{2}=3$ y $x_{3}=5$ and the function $f\left(x\right)=\sin\left(\dfrac{\pi}{6}x\right)$
Fundamental Lagrange polynomial value is 0 in all nodes except one of them, where it is equal to 1. There are as many fundamental Lagrange polynomials as nodes and they are $L_0(x),$ $L_1(x),$ $L_2(x)$ y $L_3(x).$
Let's see how they are built. First, we create polynomials that are zero in all interpolation nodes except one and we have
The nodes are
And a polynomial that is zero in the last three nodes is
If we divide this polynomial by $l_0(x_0)$
We are omitting from the numerator and denominator the term in $x_0,$ that is $(x-x_0)$ and
that is
The nodes are
And a polynomial that is zero at all but the second node is
If we divide this polynomial by $l_1(x_1)$
We are omitting from the numerator and denominator the term in $x_1,$ that is $(x-x_1)$ and
that is
The nodes are
And a polynomial that is zero at all but the third node is
If we divide this polynomial by $l_2(x_2)$
We are omitting from the numerator and denominator the term in $x_2,$ that is $(x-x_2)$ and
that is
The nodes are
And a polynomial that is zero at all but the last node is
If we divide this polynomial by $l_3(x_3)$
We are omitting from the numerator and denominator the term in $x_3,$ that is $(x-x_3)$ and
that is
We have already seen the fundamental Lagrange polynomials for our nodes (4 nodes, 4 fundamental polynomials). In general, for $x_0,$ $x_1,\ldots, x_n$ nodes we have $n+1$ fundamental Lagrange polynomials that are
It can also be expressed
And these polynomial satisfy
The interpolant polynomia is
The fundamental Lagrange polynomials are built only with the nodes. But now, to calculate the interpolation polynomial $P_3(x),$ we need the values of the function at the nodes
And taking into account the fundamental Lagrange polynomials we calculated above, the interpolation polynomial is
The interpolation polynomial, for a general case, where we have $n+1$ nodes $x_0,$ $x_1,\ldots, x_n$ will be
where $P_n(x)$ is a polynomial of degree less than or equal to $n.$
Plugging in $x=2$ in the expressions we calculate for the fundamental Lagrange polynomials
The interpolation error is
where $x_{i}$ are the interpolation points and $c$ a point of the interpolation interval. In this case, since we have four nodes interpolation
Since $c$ is unknown, even though we know it is in the interpolation interval, in our case $c\in\left(-1,5\right)$, we have to find a bound for that value
As $$\left|\sin\left(\dfrac{\pi}{6}x\right)\right|\le 1$$
then $$\left|f^{(4)}(c)\right|\le \frac{\pi^4}{6^4}(1)=\frac{\pi^4}{6^4}$$
And and error bound is
As $f(2)=\sin\left(\dfrac{\pi}{6}(2)\right)=\sin\left(\dfrac{\pi}{3}\right)=0.86603$