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

More from Math Visualization

Other simulators in this category — or see all 61.

View category →
NewSchool

Least Squares Fit

Noisy linear data; fitted slope and intercept with residuals.

Launch Simulator
NewSchool

Linear Regression: OLS, Ridge, Lasso & R²

Click/drag scatter points; fit y = β₀ + β₁x with OLS, Ridge (L2 on slope), or Lasso (L1 on slope). Spike Δy on the largest |x| point to see outlier sensitivity; compare SSE and R².

Launch Simulator
NewSchool

K-Means Clustering (Lloyd)

Click to add points, choose k, randomize centroids, then step Lloyd iterations (assign to nearest centroid, update means). Optional Gaussian-mixture demo; watch within-cluster SSE decrease.

Launch Simulator
NewSchool

DBSCAN Density Clustering

Sliders for ε and minPts on a click-built point set: core / border / noise coloring, optional ε-disks around cores, demo with scattered outliers.

Launch Simulator
NewSchool

PCA in 2D (principal components & 1D projection)

Click-built cloud: covariance eigenvectors as PC1/PC2 arrows from the mean, optional orthogonal drops to the PC1 line, and a bottom strip of PC1 scores — the standard rank-one projection coordinate.

Launch Simulator
NewSchool

Decision Tree Classifier (2D toy)

Greedy axis-aligned splits on a click-labeled scatter: compare **Gini** vs **entropy** impurity, max depth, and min-samples-per-leaf; shaded rectangles show leaf decisions, dashed lines show recursive partitions.

Launch Simulator
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

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

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

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.