On this page
A cubic spline joins a set of data points with a separate cubic polynomial on each gap. Wherever two pieces meet, they must agree on value, slope and curvature. In school you may have learnt interpolation as "fit one polynomial through all the points". Splines fix the case where that idea breaks.
What is cubic spline interpolation?
Spline interpolation fits low-degree polynomials to small groups of points instead of one high-degree polynomial through all of them. For example, it uses nine cubics between ten points rather than one degree-nine polynomial (Wikipedia: Spline interpolation). The points where the pieces join are called knots.
Take n + 1 knots, (x0, y0) to (xn, yn). Between each pair sits a cubic Si(x). At every inner knot, the two neighbouring cubics must agree on three things:
Value: both pass through the data point.
Slope: S' is the same from the left and from the right, so there is no corner.
Curvature: S'' is the same from both sides, so the bend changes smoothly.
The name comes from the flexible wooden strips that shipbuilders and draughtsmen bent through fixed points to draw smooth curves. The first mathematical use of "spline" in this sense is usually credited to I. J. Schoenberg's 1946 paper in the Quarterly of Applied Mathematics (Schoenberg 1946; history in Wikipedia: Spline (mathematics))).
What is a natural cubic spline?
First count the unknowns. With n pieces, you have 4n coefficients. The conditions above give 4n − 2 equations: 2n for the values, then n − 1 for slope and n − 1 for curvature. That leaves two equations missing, and you choose them at the ends.
A natural cubic spline sets the second derivative to zero at both ends: S''(x0) = S''(xn) = 0 (Wikipedia: Spline interpolation). Picture the wooden strip: beyond the last pin nothing holds it, so it runs straight. You can also choose other end conditions. A clamped spline fixes the end slopes. A not-a-knot spline makes the third derivative continuous at the second and second-last knots.
How do you solve a cubic spline by hand?
Take three points: (0, 1), (1, 3) and (2, 2), with equal spacing h = 1. Because the spline is natural, M0 = M2 = 0. That leaves one unknown, the middle curvature M1.
Step 1: write down the slope at a knot. Take a gap of width h whose left and right ends have curvatures Ma and Mb. At its two ends, the cubic's slope is:
at its right end: (rise)/h + h(Ma + 2Mb)/6
at its left end: (rise)/h − h(2Ma + Mb)/6
Step 2: make the slopes agree at x = 1.
Slope at x = 1 from the left piece: (3 − 1)/1 + (0 + 2M1)/6 = 2 + M1/3
Slope at x = 1 from the right piece: (2 − 3)/1 − (2M1 + 0)/6 = −1 − M1/3
Set them equal: 2 + M1/3 = −1 − M1/3. So 2M1/3 = −3, and M1 = −4.5.
Step 3: build the two cubics.
On [0, 1]: S1(x) = 1 + 2.75x − 0.75x³
On [1, 2], with t = x − 1: S2 = 3 + 0.5t − 2.25t² + 0.75t³
Step 4: check your answer. S1(1) = 1 + 2.75 − 0.75 = 3, and S2 at t = 1 is 3 + 0.5 − 2.25 + 0.75 = 2. Both pieces have slope 0.5 at x = 1. S1''(x) = −4.5x gives 0 at x = 0 and −4.5 at x = 1. S2'' = −4.5 + 4.5t gives −4.5 at t = 0 and 0 at t = 1. Every condition holds.
For equally spaced points, the same steps give a general rule: Mi−1 + 4Mi + Mi+1 = 6(yi−1 − 2yi + yi+1)/h². Check it here: 4M1 = 6(1 − 6 + 2) = −18, so M1 = −4.5. With more knots you get one such equation per inner knot, forming a tridiagonal system that you solve by elimination, row by row.
If the derivative and curvature ideas still feel shaky, the Fermi Concept Library has a lesson for every concept in mathematics, so you can revise slope and the second derivative first.
Why do splines avoid Runge's wiggles?
Carl Runge (1901) interpolated f(x) = 1/(1 + 25x²) on [−1, 1] at equally spaced points with a single polynomial. The curve oscillates near the ends, and its maximum error grows without bound as the degree rises (Wikipedia: Runge's phenomenon, citing Runge's paper in Zeitschrift für Mathematik und Physik). More points made the fit worse, not better.
A spline never raises the degree. When you add data, you add more cubic pieces, and each one only spans a single gap. No high-degree term exists to swing wildly at the edges, which is why spline interpolation avoids Runge's phenomenon (Wikipedia: Spline interpolation). Interpolating splines are normally defined as the curves through the data that minimise a roughness measure, such as the integral of squared curvature (Wikipedia: Spline (mathematics))): the wooden strip's least-strained shape.
How should you practise cubic splines?
Redo the example with (0, 0), (1, 1) and (2, 0). You should get M1 = −3 and a curve that is symmetric about x = 1.
Keep the worked example's y-values but put the points at x = 0, 2, 4, so h = 2. M1 scales by 1/h², so you should get −1.125, a quarter of −4.5.
Try four equally spaced points. You will get two equations in M1 and M2, which is your first tridiagonal system.
Before solving, count your unknowns and conditions. If the numbers don't match, you have forgotten an end condition.
For more practice, the Fermi Problem Library has worked problems with a step-by-step solver that explains the reasoning rather than printing an answer.



