Mathwords logoMathwords

Spline — Definition, Formula & Examples

A spline is a piecewise polynomial function that passes through a set of given points while maintaining smoothness at the junctions between pieces. The most common type is the cubic spline, which uses third-degree polynomials between each pair of adjacent data points.

Given n+1n+1 data points (x0,y0),(x1,y1),,(xn,yn)(x_0, y_0), (x_1, y_1), \ldots, (x_n, y_n) with x0<x1<<xnx_0 < x_1 < \cdots < x_n, a spline of degree kk is a function S(x)S(x) such that on each subinterval [xi,xi+1][x_i, x_{i+1}], S(x)S(x) is a polynomial of degree at most kk, and S(x)S(x) together with its first k1k-1 derivatives is continuous on [x0,xn][x_0, x_n].

How It Works

You start with a set of data points called knots. On each interval between consecutive knots, you define a separate polynomial. The key constraint is that neighboring polynomials must agree in value and in their derivatives (up to a specified order) at the shared knot. For a cubic spline, this means the function, its first derivative, and its second derivative are all continuous at every knot. Two additional boundary conditions (such as setting the second derivative to zero at the endpoints, called a "natural" spline) provide enough equations to determine all the polynomial coefficients uniquely.

Worked Example

Problem: Construct a natural cubic spline through the points (0, 0), (1, 1), and (2, 0). Find the spline function on each subinterval.
Step 1: Define two cubic polynomials: S0(x)S_0(x) on [0,1][0,1] and S1(x)S_1(x) on [1,2][1,2]. For a natural cubic spline, the second derivatives at the endpoints are zero: S0(0)=0S_0''(0) = 0 and S1(2)=0S_1''(2) = 0.
S0(x)=a0+b0x+c0x2+d0x3S_0(x) = a_0 + b_0 x + c_0 x^2 + d_0 x^3
Step 2: Apply interpolation conditions (S0(0)=0S_0(0)=0, S0(1)=1S_0(1)=1, S1(1)=1S_1(1)=1, S1(2)=0S_1(2)=0), continuity of first and second derivatives at x=1x=1, and the natural boundary conditions. Solving the resulting system of equations yields:
S0(x)=32x12x3S_0(x) = \tfrac{3}{2}x - \tfrac{1}{2}x^3
Step 3: Similarly, writing S1S_1 in terms of (x1)(x-1) for convenience and solving:
S1(x)=1+0(x1)32(x1)2+12(x1)3S_1(x) = 1 + 0(x-1) - \tfrac{3}{2}(x-1)^2 + \tfrac{1}{2}(x-1)^3
Answer: The natural cubic spline is S0(x)=32x12x3S_0(x) = \tfrac{3}{2}x - \tfrac{1}{2}x^3 on [0,1][0,1] and S1(x)=132(x1)2+12(x1)3S_1(x) = 1 - \tfrac{3}{2}(x-1)^2 + \tfrac{1}{2}(x-1)^3 on [1,2][1,2]. Both pieces join smoothly at x=1x=1 with matching value, first derivative, and second derivative.

Why It Matters

Splines are the backbone of computer-aided design (CAD), computer graphics, and font rendering. In numerical analysis courses, cubic spline interpolation is preferred over high-degree polynomial interpolation because it avoids the wild oscillations described by Runge's phenomenon. Engineers and data scientists use splines for smooth curve fitting in everything from aerospace surface modeling to smoothing noisy sensor data.

Common Mistakes

Mistake: Forgetting to impose boundary conditions, leaving the cubic spline system underdetermined.
Correction: A cubic spline through n+1n+1 points has 4n4n unknown coefficients but only 4n24n - 2 equations from interpolation and continuity. You need two additional boundary conditions (e.g., natural, clamped, or not-a-knot) to obtain a unique solution.