Natural Cubic Spline
Join three data points with a smooth piecewise cubic and inspect interpolation, derivative continuity and natural end conditions.
By Riano · Published · Updated · Report a correction
Natural Cubic Spline
Concept Overview
A cubic spline is a piecewise function consisting of cubic polynomials that connect a set of data points (knots). A natural cubic spline enforces the constraint that the second derivative is exactly zero at the endpoints. It provides C2 continuity everywhere, meaning its value, first derivative, and second derivative are all continuous across the interior knots.
Worked Example: Solving the System
Consider three knots at x0=0, x1=1, x2=2 with values y0=1, y1=2, y2=0.
- Identify step sizes: We have h0 = 1 - 0 = 1, and h1 = 2 - 1 = 1.
- Set up natural conditions: The second derivatives at the boundaries are zero: M0 = 0, M2 = 0.
- Solve for interior second derivative: The continuity of the first derivative at the interior knot x1=1 gives the equation:
(h0/6)M0 + ((h0+h1)/3)M1 + (h1/6)M2 = (y2 - y1)/h1 - (y1 - y0)/h0
Substituting values:
(1/6)*0 + (2/3)M1 + (1/6)*0 = (0 - 2)/1 - (2 - 1)/1 = -2 - 1 = -3
(2/3)M1 = -3 ⇒ M1 = -4.5. - Evaluate the piece [0, 1]:For x = 0.5, we evaluate piece 0 using:
S0(x) = (M0/6)(1-x)3 + (M1/6)x3 + (y0 - M0/6)(1-x) + (y1 - M1/6)x
S0(0.5) = (0)(0.125) + (-4.5/6)(0.125) + (1)(0.5) + (2 - (-4.5/6))(0.5)
= 0 - 0.09375 + 0.5 + 1.375 = 1.78125.
Experiment: End Conditions
Open the Natural Cubic Spline module.
- Select Value at x=0 to -2, and select Value at x=2 to -1.
- Select Value at x=1 to 2 and Probe x to 0.
- Observe that the Second Derivative at this endpoint is 0.
- The endpoint second derivative is zero, while the first derivative here is 5.75. Zero second derivative at a boundary does not establish an inflection point or prevent overshoot. Change Probe x to 2: the second derivative is again zero, while the first derivative is -4.75. The module does not extrapolate beyond the endpoints.
Limitations: Reproducing True Functions
The natural cubic spline imposes M0=0 and M2=0 artificially. This boundary condition means it cannot perfectly reproduce polynomials of degree 2 or higher unless their second derivative at the boundaries naturally happens to be zero. For instance, interpolating points from y=x2 will not yield the exact parabola because a true parabola has a constant non-zero second derivative, which conflicts with the zero boundary condition.
Primary References
The mathematical derivation of natural endpoints and calculating piece derivatives can be reviewed below.
- Fasshauer, G., Chapter 1, Illinois Institute of Technology. https://math.iit.edu/~fass/478578_Chapter_1.pdf
Experience it interactively
Adjust parameters, observe in real time, and build deep intuition with Riano’s interactive Natural Cubic Spline module.
Try Natural Cubic Spline on Riano →