Exercises — Cubic spline interpolation — natural, clamped
Throughout, we reuse the notation from the parent:
- is the width of interval (the gap between two neighbouring -values).
- is the moment — the second derivative (the bendiness) of the spline at node .
- The interior recurrence for is
We reprint the two piece formulas we keep using, so nothing is assumed:
Level 1 — Recognition
Problem 1.1 (L1)
State, in plain words, what each of the following equals for a cubic spline : (a) , (b) continuity of at an interior node , (c) the natural boundary condition, (d) the clamped boundary condition.
Recall Solution 1.1
(a) : the piece on must pass through the left data point — this is interpolation. (b) : the slope coming into node from the left piece equals the slope leaving on the right piece — no kink. (c) Natural: and — zero curvature at the two ends (the ruler is relaxed/straight there). (d) Clamped: and — the end slopes are pinned to given numbers.
Problem 1.2 (L1)
For data at , compute all the widths . How many unknown moments are there, and how many interior equations does the recurrence give?
Recall Solution 1.2
, , . There are moments . The interior recurrence runs over , giving 2 interior equations. We are 2 short (4 unknowns, 2 equations), so we need 2 boundary conditions — exactly natural or clamped.
Level 2 — Application
Problem 2.1 (L2)
Data with equal spacing . Build the natural spline: find .
Recall Solution 2.1
Natural . Only is unknown. Interior recurrence at with : So . Result: . The negative middle moment means the spline is concave-down at the peak, as expected for a hump.
Problem 2.2 (L2)
Using the moments from Problem 2.1, write the cubic on and verify and .
Recall Solution 2.2
Use the piece formula with , , , , , , , :
Simplify: , and . So Check ✓. ✓. And , so ✓ (natural).
Level 3 — Analysis
Problem 3.1 (L3)
For the same data , build the clamped spline with and . Find , then compare with the natural case and explain the difference.
Recall Solution 3.1
Boundary equations (from parent, ): Left: , i.e. . Right: , i.e. . Interior (): (RHS from Problem 2.1). Solve: from Left, ; from Right, . Substitute into interior: Multiply by 2: Then and . Result: . Comparison: Natural gave (zero end curvature). Clamped forces : the spline must bend at the left end to drag its slope up to the imposed . Curvature is the price of pinning a slope.
Problem 3.2 (L3)
Explain why the spline coefficient matrix is diagonally dominant and why that guarantees the moments are uniquely determined. Reference the tridiagonal structure.
Recall Solution 3.2
Each interior row is The diagonal entry is . The two off-diagonal entries are and , both positive. Their sum is , which is strictly less than the diagonal . So in every row — that is the definition of strict diagonal dominance. A strictly diagonally dominant tridiagonal matrix is non-singular, so the system has a unique solution. Practically, the Tridiagonal systems & Thomas algorithm solves it in with no pivoting needed — the dominance keeps the elimination numerically stable.
Level 4 — Synthesis
Problem 4.1 (L4)
Data , equal spacing . Build the natural spline: set up the system for , solve, and state all four moments.
Recall Solution 4.1
Here , nodes . Natural . Interior recurrence at and , all so diagonal , off-diagonals : : With : . : With : . Solve . From the first, . Substitute: Then Result: The antisymmetric data produces antisymmetric moments — a clean sanity check.
Problem 4.2 (L4)
Using the moments from 4.1, write on and evaluate the spline's slope at the interior node from both the left piece and the right piece to confirm slope continuity there.
Recall Solution 4.2
Left piece on : , , , . Its slope from the boxed formula: At : , , so Right piece on : , , . At : , so Both give ✓ — slope is continuous at , confirming the whole construction. See the assembled curve below.

Level 5 — Mastery
Problem 5.1 (L5)
Degenerate case. Only two points are given: , and you build a natural cubic spline. What curve do you actually get, and why does "cubic spline" collapse here? Contrast with a clamped spline having .
Recall Solution 5.1
With there is a single interval and moments only. Natural sets and — and there are no interior nodes, so the recurrence gives no equations at all. Both moments are already fixed. Since is linear and vanishes at both ends, on . A function with zero second derivative is a straight line. Interpolating : So the natural spline degenerates to the linear interpolant — no cubic curvature survives. Clamped: now are pinned via the boundary equations. Left: with : . Right: : . Solve : from these, multiply the first by 2: ; subtract the second: , then . So : the clamped spline is a genuine cubic (it must curve to hit slope at the right end). Takeaway: with only two points, natural is boring (a line) but clamped still carries real cubic information.
Problem 5.2 (L5)
Non-uniform spacing. Data (three collinear-at-height-zero points, but unequal gaps ). Build the natural spline. Predict the answer first, then verify by the recurrence, and explain what this teaches about splines through collinear data.
Recall Solution 5.2
Prediction: all , so the flat line interpolates and is with zero curvature — natural conditions are satisfied. So we expect all moments zero. Verify: Natural . Interior at with : RHS . LHS . So . All moments zero , matching the prediction even with the unequal spacing. Lesson: a natural spline reproduces a straight line exactly (here the zero line). This is why splines don't suffer the Runge wobble — they add curvature only where the data demands it, and the tridiagonal structure handles non-uniform automatically. (This connects to B-splines, where the flat-data reproduction property is built in.)
Recall Final self-check — cover the answers
- In Problem 2.1, what was ? ::: .
- In Problem 3.1 (clamped), what was ? ::: .
- In Problem 4.1, the four moments were? ::: .
- What slope value confirmed continuity at in 4.2? ::: from both pieces.
- What did the two-point natural spline collapse to (5.1)? ::: The straight line .