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
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
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.
More from Math Visualization
Other simulators in this category — or see all 33.
Least Squares Fit
Noisy linear data; fitted slope and intercept with residuals.
Convolution (pulses)
Two rectangular pulses; overlap length at τ = 0.
Euler vs RK4 (Pendulum)
Same nonlinear pendulum ODE and step h; Euler vs RK4 side by side.
Lotka–Volterra
N′ = αN−βNP, P′ = δNP−γP; phase plane RK4; equilibrium dot.
Logistic Growth
dN/dt = rN(1−N/K); exact S-curve vs carrying capacity K.
Logistic Map Bifurcation
x_{n+1}=rx_n(1−x_n): scan r, plot attractors — period doubling to chaos (Feigenbaum cascade).