Skip to main content

Cubic spline and its advantage

Short answer

Cubic spline interpolation fits a piecewise cubic polynomial between each pair of data points, ensuring continuity of the function, slope, and curvature at the joints. Its advantages over polynomial interpolation include avoiding oscillations with many points, local influence of data changes, and suitability for any spacing.

What is Cubic Spline Interpolation? What is the advantage of this method over polynomial interpolation?

Cubic spline interpolation

A cubic spline interpolates n+1 data points (x₀, y₀) … (xₙ, yₙ) by a set of n cubic polynomials Sᵢ(x), one on each sub-interval [xᵢ, xᵢ₊₁], joined smoothly at the knots (the data points).

y
│        ●─── S1 ───●
│     ●╱              ╲● ─ S2 ─ ●
│  S0 ╱
│ ●──╱
└────────────────────────────────── x
 x0   x1        x2        x3
 one cubic per interval, smoothly joined

Conditions

For i = 0 … n−1, Sᵢ(x) = aᵢ + bᵢ(x − xᵢ) + cᵢ(x − xᵢ)² + dᵢ(x − xᵢ)³ (4n unknowns) must satisfy:

  1. Interpolation: Sᵢ(xᵢ) = yᵢ and Sᵢ(xᵢ₊₁) = yᵢ₊₁.
  2. Continuity of slope at interior knots: Sᵢ′(xᵢ₊₁) = Sᵢ₊₁′(xᵢ₊₁).
  3. Continuity of curvature at interior knots: Sᵢ″(xᵢ₊₁) = Sᵢ₊₁″(xᵢ₊₁).
  4. Two end conditions. For the natural spline: S″(x₀) = S″(xₙ) = 0.

Working formula

Let Mᵢ = S″(xᵢ) and hᵢ = xᵢ₊₁ − xᵢ. Then

Sᵢ(x) = Mᵢ(xᵢ₊₁ − x)³/(6hᵢ) + Mᵢ₊₁(x − xᵢ)³/(6hᵢ)
        + (yᵢ/hᵢ − Mᵢhᵢ/6)(xᵢ₊₁ − x) + (yᵢ₊₁/hᵢ − Mᵢ₊₁hᵢ/6)(x − xᵢ)

and the Mᵢ come from the tridiagonal system (i = 1 … n−1), with M₀ = Mₙ = 0 for the natural spline:

hᵢ₋₁Mᵢ₋₁ + 2(hᵢ₋₁ + hᵢ)Mᵢ + hᵢMᵢ₊₁ = 6[(yᵢ₊₁ − yᵢ)/hᵢ − (yᵢ − yᵢ₋₁)/hᵢ₋₁]

Steps: find hᵢ, form the system, solve for the Mᵢ, then evaluate the Sᵢ for the interval containing the required x.

Advantages over polynomial interpolation

Polynomial interpolationCubic spline
One polynomial of degree n for n+1 points; degree rises with the number of pointsAlways degree 3, however many points
Large oscillations between points for high degree (Runge's phenomenon)Smooth, stable curve without wild swings
Changing one data point changes the whole curveLocal effect: a change mainly affects nearby intervals
Error can grow near the ends of the intervalError is small and uniform, of order h⁴
Only the function values are matchedSlope and curvature are also continuous, so the curve looks smooth
Newton's difference formulas need equal spacing (Lagrange's formula does not)Works directly with unequal spacing
Solving a large system or building high-degree terms is ill-conditionedTridiagonal system, solved easily and stably

Hence splines are widely used in curve design, computer graphics and data smoothing.

✓ Answer checked by Claude Opus 5.5 (high effort)

All Numerical Method chapter 4 questions →