5.2: Piecewise Linear Interpolation
Instead of constructing a single global polynomial that goes through all the points, one can construct local polynomials that are then connected together. In the the section following this one, we will discuss how this may be done using cubic polynomials. Here, we discuss the simpler case of linear polynomials. This is the default interpolation typically used when plotting data.
Suppose the interpolating function is \(y=g(x)\) , and as previously, there are \(n+1\) points to interpolate. We construct the function \(g(x)\) out of \(n\) local linear polynomials. We write
\[g(x)=g_{i}(x), \quad \text { for } x_{i} \leq x \leq x_{i+1} \nonumber \]
where
\[g_{i}(x)=a_{i}\left(x-x_{i}\right)+b_{i} \nonumber \]
and \(i=0,1, \ldots, n-1\) .
We now require \(y=g_{i}(x)\) to pass through the endpoints \(\left(x_{i}, y_{i}\right)\) and \(\left(x_{i+1}, y_{i+1}\right)\) . We have
\[\begin{aligned} y_{i} &=b_{i} \\ y_{i+1} &=a_{i}\left(x_{i+1}-x_{i}\right)+b_{i} . \end{aligned} \nonumber \]
Therefore, the coefficients of \(g_{i}(x)\) are determined to be
\[a_{i}=\frac{y_{i+1}-y_{i}}{x_{i+1}-x_{i}}, \quad b_{i}=y_{i} \nonumber \]
Although piecewise linear interpolation is widely used, particularly in plotting routines, it suffers from a discontinuity in the derivative at each point. This results in a function which may not look smooth if the points are too widely spaced. We next consider a more challenging algorithm that uses cubic polynomials.