We start from a table of points for
for the function . That makes points and
intervals between them. The cubic spline interpolation is a piecewise
continuous curve, passing through each of the values in the table.
There is a separate cubic polynomial for each interval, each with its
own coefficients:
Since there are intervals and four coefficients for each we
require a total of parameters to define the spline . We
need to find independent conditions to fix them. We get two
conditions for each interval from the requirement that the cubic
polynomial match the values of the table at both ends of the interval:
We still need more conditions. Since we would like to make the
interpolation as smooth as possible, we require that the first and
second derivatives also be continuous:
With coefficients and linear conditions it is straightforward to work out the equations that determine them. The conditions can be reduced easily to a tridiagonal system with the coefficients as the unknowns. Once solved, the remaining coefficients are easily determined. There are many good codes in the public domain.
Cubic splines are popular because they are easy to implement and produce a curve that appears to be seamless. As we have seen, a straight polynomial interpolation of evenly spaced data tends to build in distortions near the edges of the table. Cubic splines avoid this problem, but they are only piecewise continuous, meaning that a sufficiently high derivative (third) is discontinous. So if the application is sensitive to the smoothness of derivatives higher than second, cubic splines may not be the best choice.