Calculator · Engineering Mathematics

Cubic Spline Calculator

Fit a natural cubic spline through your data: a separate cubic on every interval, joined so that the value, the slope and the curvature all match at each knot.

Data points

5 of at most 32 points. Duplicate x values are refused, never merged; unsorted points are sorted by x before use.

Query

Results

Estimate y(2.5)6.232
MethodNatural Cubic Spline
StatusInterpolation — inside the data span
Data points5
Data span[0, 4]
Interval used[2, 3]
Segment index2
End conditionNatural: S″ = 0 at both ends

Segment used

Interval[2, 3]
a (value at xᵢ)4
b (slope at xᵢ)4
c (half the curvature at xᵢ)0.8571
d (cubic coefficient)0.1429

Sᵢ(x) = a + b·Δx + c·Δx² + d·Δx³ with Δx = x − 2.

Data and spline

Every data point, the natural cubic spline through them and the target. The curve is a dense polyline of the actual spline; no display smoothing is applied, so any overshoot shown is real.

Continue

Open in Interpolation Lab

The dataset and the target continue into the Lab with the natural cubic spline enabled. No reference function is carried over, because this calculator does not have one.

Assumptions & validity

  • · At least 2 and at most 32 points, the documented browser-safety cap. A larger dataset is refused, never truncated.
  • · All abscissas must be distinct; duplicate x values are rejected and never merged.
  • · All coordinates must be finite.
  • · Unsorted points are sorted by x before the spline is built.
  • · V1 imposes the NATURAL end condition only: S″ = 0 at both ends. Clamped, not-a-knot and periodic ends are out of scope rather than approximated.
  • · Two points give a single interval, where the natural condition forces the straight line between them.
  • · Outside the data span the nearest end cubic is continued. That is extrapolation and is labelled as such.
  • · A spline is smooth, not shape preserving: it can overshoot between points even when the data is monotone.

Technical reference

Sᵢ(x) = aᵢ + bᵢ·Δx + cᵢ·Δx² + dᵢ·Δx³, Δx = x − xᵢ, x ∈ [xᵢ, xᵢ₊₁]

hᵢ = xᵢ₊₁ − xᵢ

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

Natural ends: M₀ = Mₙ = 0

aᵢ = yᵢ, cᵢ = Mᵢ/2, dᵢ = (Mᵢ₊₁ − Mᵢ)/(6hᵢ), bᵢ = (yᵢ₊₁ − yᵢ)/hᵢ − hᵢ(2Mᵢ + Mᵢ₊₁)/6

Sᵢ
the cubic piece on the ith interval
Mᵢ
second derivative S″ at node i
hᵢ
width of the ith interval
aᵢ … dᵢ
local coefficients of the ith cubic

The spline is C⁰, C¹ and C² across every interior knot: value, slope and curvature all match. That is what distinguishes it from joining the points with separate cubics fitted piece by piece.

Those continuity conditions plus the two end conditions determine the spline uniquely, and reduce to a symmetric tridiagonal system in the nodal second derivatives. It is solved here by the Thomas algorithm; for distinct abscissas the matrix is strictly diagonally dominant, so no pivoting is needed.

The natural end condition sets the curvature to zero at the first and last node. It is a CHOICE, not a property of your data: it makes the spline straighten out at the ends, which is often wrong for data that is still curving there.

A spline reproduces constant and linear data exactly, because those already satisfy every continuity and end condition.

It is not shape preserving. Monotone data can produce a spline that dips below or rises above its neighbours between points; if that is unacceptable, a monotone method is required instead — one is not offered here.

Each interval's cubic is local: moving one data point changes the whole spline in principle, but the effect decays rapidly with distance, unlike the global polynomial.

Extrapolation continues the end cubic beyond its own interval. A cubic leaves its data quickly, so treat any value outside the span as unsupported.

Related tools