PhysSandbox
Classical MechanicsWaves & SoundElectricity & MagnetismOptics & LightGravity & OrbitsLabs
🌙Astronomy & The Sky🌡️Thermodynamics🌍Biophysics, Fluids & Geoscience📐Math Visualization🔧Engineering🧪Chemistry

Related simulators

Continue with similar topics in this category — or all 85 in Math Visualization.

View category →
NewUniversity / research

2D Phase Portrait (ODE)

Launch Simulator

Direction field and click-to-trace trajectories for planar systems: harmonic, damped, saddle, nodes, foci, pendulum (RK4).

NewUniversity / research

MinD / MinE Oscillation (E. coli Rod)

Launch Simulator

1D reaction–diffusion: membrane MinD u, fast MinE v; pole-to-pole oscillation; division plane at time-averaged MinD minimum.

NewSchool

Taylor Polynomial

Launch Simulator

sin, cos, or exp vs Taylor sum about center a up to order n.

NewSchool

Bézier & de Casteljau

Launch Simulator

Drag control points; live recursive linear-interpolation scaffolding evaluates B(t).

NewUniversity / research

Conjugate Gradient Solver

Launch Simulator

SPD system Ax=b as quadratic minimization: contour geometry, CG vs steepest descent path, residual norm, and condition number.

NewUniversity / research

Lorenz Strange Attractor

Launch Simulator

σ, ρ, β ODEs; sensitive butterfly in (x,z) projection — RK4 trace.

PhysSandbox

Interactive physics, chemistry, and engineering simulators for students, teachers, and curious minds.

Physics

  • Classical Mechanics
  • Waves & Sound
  • Electricity & Magnetism

Science

  • Optics & Light
  • Gravity & Orbits
  • Astronomy & The Sky

More

  • Thermodynamics
  • Biophysics, Fluids & Geoscience
  • Math Visualization
  • Engineering
  • Chemistry

© 2026 PhysSandbox. Free interactive science simulators.

PrivacyTermsContact
Home/Math Visualization/Lagrange vs Cubic Spline

Lagrange vs Cubic Spline

Click knots: Lagrange polynomial vs natural cubic spline; Runge preset shows edge oscillations.

Curves

Presets

Click empty plot to add a knot (max 18). Drag a knot to move it. Shift+click removes the nearest knot. Equal-spacing plus steep “Runge” data makes high-degree Lagrange oscillate at the edges; the spline stays smooth.

Shortcuts

  • •Shift+click — remove nearest knot
  • •R — reset Runge demo

Measured values

Knots n11
Polynomial degree10

About this model

Polynomial interpolation finds a smooth curve that passes exactly through a given set of knots (data points). Lagrange interpolation constructs a single global polynomial of degree at most n−1 through n distinct x-values using the classical product-form basis polynomials. While elegant and unique, this global polynomial can exhibit large oscillations between knots when the degree is high and knots are evenly spaced—a phenomenon often illustrated with Runge's example. Cubic splines take a different approach: they use a separate cubic polynomial on each subinterval between consecutive knots, imposing continuity of the function, its first derivative, and its second derivative at interior knots. A natural cubic spline additionally sets the second derivative to zero at the two endpoints, which corresponds to minimal curvature in a certain variational sense among all twice-differentiable interpolants. This simulator lets learners place and drag knots on a plane, compare the Lagrange interpolant (blue) with the natural cubic spline (green), and load presets including an evenly spaced Runge-style bell curve where the polynomial wiggles dramatically near the edges while the spline remains visually tame. It reinforces the distinction between a single high-degree global fit and a piecewise low-degree construction, a central idea in numerical analysis, computer graphics, and data smoothing.

Who it's for: Undergraduate students in numerical analysis, applied mathematics, or scientific computing, and anyone learning interpolation before splines and regression.

Key terms

  • Lagrange interpolation
  • Runge phenomenon
  • Natural cubic spline
  • Piecewise polynomial
  • Tridiagonal system
  • Spline continuity
  • Interpolation vs approximation

How it works

Lagrange interpolation is the unique polynomial of degree ≤ n−1 through n distinct knots. Natural cubic splines use a separate cubic on each segment, with matching values, continuous first and second derivatives at interior knots, and zero second derivative at the endpoints. Splines avoid the wild edge oscillations (Runge phenomenon) that high-degree polynomials often show.

Key equations

Lagrange: P(x) = Σⱼ yⱼ · Πᵢ≠ⱼ (x−xᵢ)/(xⱼ−xᵢ)
Spline: cubic on each [xᵢ,xᵢ₊₁]; S, S′, S″ continuous inside; S″(x₀)=S″(xₙ₋₁)=0

Frequently asked questions

Why does the blue Lagrange curve oscillate so wildly with many evenly spaced points?
This is the Runge phenomenon: for some smooth functions, uniform spacing forces the unique interpolating polynomial of high degree to develop large overshoots near the interval ends. The error can grow as the degree increases, even though the polynomial still passes exactly through every knot.
What does “natural” mean for the cubic spline?
It sets the second derivative to zero at the two boundary knots. That choice pins down the extra degrees of freedom needed to close the system and often yields the smoothest-looking interpolant in a precise mathematical sense (minimal total squared second derivative) subject to passing through all knots.
Does the spline always look closer to what I “expect” than the polynomial?
Often yes for visualization, because each piece is only cubic and the global smoothness constraints prevent the explosive edge behavior typical of high-degree polynomials. However, splines still interpolate exactly—if you want noise rejection, you usually switch to least squares or penalized splines rather than exact interpolation.
Why must x-coordinates of knots be distinct?
A function graph cannot pass through two different y values at the same x. Mathematically, the Lagrange denominators (x_j − x_i) would vanish, and the Vandermonde-style system for a single polynomial would be singular. The simulator enforces a minimum horizontal separation when you add knots and nudges overlaps apart after dragging.