Cubic splines

Piecewise interpolation with one cubic per interval: the continuity conditions, the tridiagonal system that fixes the coefficients, natural splines and how to solve them.

Why piecewise

A single high-degree polynomial oscillates between nodes (Runge phenomenon). Splines avoid this by using a different, low-degree polynomial on each interval, joined smoothly. The most used are cubic.

Si(x)=ai+bi(xxi)+ci(xxi)2+di(xxi)3,i=0,,n1S_i(x)=a_i+b_i(x-x_i)+c_i(x-x_i)^2+d_i(x-x_i)^3,\qquad i=0,\dots,n-1

Cubic spline conditions

  1. Interpolates: S(x_i)=f(x_i) at each node.
  2. Piecewise: S(x)=S_i(x) on [x_i, x_{i+1}].
  3. Value continuity at shared nodes: S_{i+1}(x_{i+1})=S_i(x_{i+1}).
  4. First-derivative continuity: S_{i+1}'(x_{i+1})=S_i'(x_{i+1}).
  5. Second-derivative continuity: S_{i+1}''(x_{i+1})=S_i''(x_{i+1}).
  6. Boundary conditions: natural (S''=0 at the ends) or clamped (S' fixed at the ends).

The tridiagonal system

Imposing the conditions turns the computation of the 4n4n coefficients into a linear system for the cic_i. With hi=xi+1xih_i=x_{i+1}-x_i and ai=f(xi)a_i=f(x_i):

hi1ci1+2(hi1+hi)ci+hici+1=3hi(ai+1ai)3hi1(aiai1)h_{i-1}c_{i-1}+2(h_{i-1}+h_i)c_i+h_i c_{i+1}=\frac{3}{h_i}(a_{i+1}-a_i)-\frac{3}{h_{i-1}}(a_i-a_{i-1})

Once the cic_i are solved, the other coefficients follow directly:

bi=1hi(ai+1ai)hi3(2ci+ci+1),di=ci+1ci3hib_i=\frac{1}{h_i}(a_{i+1}-a_i)-\frac{h_i}{3}(2c_i+c_{i+1}),\qquad d_i=\frac{c_{i+1}-c_i}{3h_i}