next up previous
Next: Cubic Spline Smoothing Up: cubic_spline Previous: cubic_spline

Cubic Spline Interpolation

We start from a table of points $[x_i,y_i]$ for $i = 0,1,\ldots{},n$ for the function $y = f(x)$. That makes $n+1$ points and $n$ 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:

\begin{displaymath}
S_i(x) = a_i(x - x_i)^3 + b_i(x - x_i)^2 + c_i(x - x_i) + d_i  \
\mbox{for $x \in [x_i,x_{i+1}].$}
\end{displaymath}

together, these polynomial segments are denoted $S(x)$, the spline.

Since there are $n$ intervals and four coefficients for each we require a total of $4n$ parameters to define the spline $S(x)$. We need to find $4n$ 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:

\begin{displaymath}
S_i(x_i) = y_i,     S_i(x_{i+1}) = y_{i+1}.
\end{displaymath}

Notice that these conditions result in a piecewise continuous function.

We still need $2n$ 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:

\begin{displaymath}
S^\prime_{i-1}(x_i) = S^\prime_i(x_i),   \
S^{\prime\prime}_{i-1}(x_i) = S^{\prime\prime}_i(x_i).
\end{displaymath}

These conditions apply for $i = 1,2,\ldots{},n-1$, resulting in $2(n-1)$ constraints. So we need two more conditions to completely fix the spline. There are some standard choices left to the user:
  1. ``natural'' $S_0^{\prime\prime}(x_0) = 0, \ \ \
S_{n-1}^{\prime\prime}(x_n) = 0$
  2. ``clamped'' $S_0^\prime(x_0) = f^\prime(x_0), \ \ \
S_{n-1}^{\prime}(x_n) = f^\prime(x_n)$
Other choices are possible if the function is periodic. Which is best depends on the application.

With $4n$ coefficients and $4n$ 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 $c_i$ 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.


next up previous
Next: Cubic Spline Smoothing Up: cubic_spline Previous: cubic_spline