We have already seen how the Lagrange interpolation polynomial is constructed. How could the result be improved? That is, how to make the error smaller? Adding nodes? The problem is that if we increase the number of nodes, the degree of the interpolation polynomial increases. And high degree polynomials can give very large errors due to large oscillations.
For example, in the following example, we interpolate the function $$f(x) = \frac{1}{1+25x^2}$$ with $11$ equally spaced nodes in the interval $[-1,1]$ and the relative error at points near the extremes of the interval is huge.
For this reason, high degree interpolation polynomials are rarely used. A solution is to use the Chebysev nodes, which are the zeros of the Chebysev polynomial (they are in the interval $[-1,1]$ but with a linear transformation they can be obtained for any closed interval).
The problem is that we cannot always choose the nodes.
The most commonly used solution is piecewise interpolation. The interval is divided into subintervals and in each of them, it is interpolated with a polynomial of degree 1, 2 or 3. In practice the most common are
For the nodes $x_{0}=-1,$ $x_{1}=1,$ $x_{2}=3$ and $x_{3}=5$ and the function $$f\left(x\right)=\sin\left(\dfrac{\pi}{6}x\right)$$
Piecewise linear interpolation consists of joining the nodes with line segments and approximating the value of the function with its value on these lines.
We want to approximate the function at $x = 2.$ First we have to choose the nodes that we will use to interpolate with a line. We will take the two nodes closest to $x = 2,$ which are $1$ and $3.$ From now on we forget about the other nodes and rename these nodes as
The function values at these nodes are
We can interpolate using the Lagrange form and then the linear interpolation polynomial on the interval $[1,3]$ is
And the value in $x=2$ es
The divided difference table is
And the interpolation polynomial in Newton's form
And the value in $x=2$ is
The interpolation error is given by the formula
which is the same as in the Lagrangian interpolation since we only consider the interval $[1,3]$ and we use only two nodes, it is a Lagrangian interpolation. For two nodes, this formula is
The value $c$ is unknown, although we know it is in the interpolation interval, in this case $c\in\left(1,3\right)$ and we have to find a bound for that value. We calculate the second derivative of the function
As $c\in(1,3)$ the value $$\dfrac{\pi}{6} c\in \left(\dfrac{\pi}{6}(1) , \dfrac{\pi}{6}(3)\right) = \left(\dfrac{\pi}{6} , \dfrac{\pi}{2}\right) = (30^o,90^o)$$
And since the sine function takes the maximum value for $90^o$ $$\left|\sin\left(\dfrac{\pi}{6}c\right)\right|\lt 1$$
Then $$\left|f''(c)\right|\lt \frac{\pi^2}{6^2}$$
And therefore we can give as error bound
As $f(2)=\sin\left(\dfrac{\pi}{6}(2)\right)=\sin\left(\dfrac{\pi}{3}\right)=0.86603$
We see that
Can we improve this result? Yes, increasing the number of nodes. For example, if instead of 4 equally spaced nodes we use 8 equally spaced nodes the result of the linear interpolation, graphically, will be
Let us now compare, for the same nodes, interpolation with a high degree polynomial and piecewise linear interpolation. We see that, in general, piecewise linear interpolation is better.