Cubic Spline Interpolation Calculator

Fit a smooth natural cubic spline through your points and evaluate it at any x.

Formula

Between each pair of neighbouring points xᵢ and xᵢ₊₁ the spline is its own cubic:

Sᵢ(x) = aᵢ + bᵢ·t + cᵢ·t² + dᵢ·t³,   t = x − xᵢ

The pieces pass through every point and join with the same slope and curvature, which makes the curve look smooth. A natural spline also has zero curvature at both ends.

Example

Through (0, 0), (1, 1) and (2, 0), the curvature at the middle point works out to M₁ = −3. The first piece is S₀(x) = 1.5x − 0.5x³, so

S(0.5) = 1.5 × 0.5 − 0.5 × 0.125 = 0.6875

Straight-line linear interpolation would give 0.5.

How the coefficients are found

Let hᵢ = xᵢ₊₁ − xᵢ and let Mᵢ be the second derivative at each point. Matching slopes at every inner point gives one equation per point:

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

With M₀ = Mₙ = 0 this is a tridiagonal system, solved in one pass. Then aᵢ = yᵢ, cᵢ = Mᵢ/2, dᵢ = (Mᵢ₊₁ − Mᵢ)/(6hᵢ) and bᵢ = (yᵢ₊₁ − yᵢ)/hᵢ − hᵢ(2Mᵢ + Mᵢ₊₁)/6.

When to use a spline
  • Smooth physical data, such as calibration curves, material properties or trajectories, where straight segments look too jagged.
  • Many points, where a single polynomial would oscillate.
  • Not for noisy measurements: a spline goes through every point, noise included. Use a least-squares fit for those.
  • If you only need straight segments between rows, the table calculator is simpler and never overshoots.

FAQ

What is a natural cubic spline?

A spline whose second derivative is zero at the first and last point, so the curve straightens out at both ends. It is the most common default when nothing is known about the end slopes.

Spline or Lagrange polynomial?

With more than about 5 points, use the spline. A single Lagrange polynomial through many points tends to swing wildly between them; a spline stays close to the data.

Why does my result differ from Excel or SciPy?

Check the end condition. SciPy’s CubicSpline defaults to “not-a-knot”, while this calculator uses a natural spline. Away from the ends the two are usually very close.