Lab · Engineering Mathematics

Numerical Interpolation Lab

Run piecewise linear, Lagrange and natural cubic spline interpolation on one dataset and one target at the same time, and see where they agree, where they diverge, and — only when a reference function exists — which of them is actually right.

Dataset

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

Query and reference

Operators + − * / ^, parentheses, pi and e, and sin, cos, tan, asin, acos, atan, exp, sqrt, abs, ln, log, log10. Write 2*x, not 2x.

A reference is supplied and treated as authoritative, so the table reports the absolute error relative to that reference, |estimate − f(x)|, at the target. It is a discrepancy against your reference, not an estimate of anything.

Methods

A method that is off is not evaluated at all. At most 32 points; duplicate x values are refused and never merged.

Presets

Comparison

MethodEstimate at x = 4Points / degree or segmentStatusAbsolute error vs reference
Piecewise Linear102 points · segment 0Interpolation — inside the data span6

Reference value at the target: 16. The error column is the absolute error relative to that supplied reference, |estimate − f(x)|, and nothing else.

Data and interpolants

The source data is authoritative and always visible, together with every enabled interpolant, the optional reference curve and the target. Curves are dense polylines of the actual methods; no smoothing is applied, and a non-finite reference sample leaves a gap.

What this Lab models

One dataset, one target abscissa, and up to three interpolants evaluated on exactly the same data. Each method answers the same question — what value belongs at this x? — and the point of the Lab is that they answer it differently, for reasons that are properties of the methods rather than of your data.

Model scope

  • · Inside the data span the methods INTERPOLATE. Outside it they EXTRAPOLATE, which is a different claim entirely, and every row says which one it made.
  • · Piecewise Linear is local and piecewise degree-1: it only uses the two points bracketing the target, and it never overshoots. Degree 1 is the polynomial degree, not an error order — on a smooth function with a refined regular mesh the interpolation error is typically second order in the spacing.
  • · Lagrange is a single global polynomial of degree n − 1: every point influences every value, and the curve is exact at all nodes.
  • · The natural cubic spline is piecewise cubic with matching value, slope and curvature at each knot, and zero curvature at the two ends. It is smooth but NOT shape preserving, so it can overshoot.
  • · Equally spaced nodes with a high-degree polynomial produce the Runge phenomenon: try the Runge preset and watch the polynomial oscillate near the ends while the piecewise methods stay calm.
  • · Duplicate abscissas are invalid data, not a rounding problem: they are refused, never merged or averaged.
  • · Without a reference function, the differences between methods are NOT error estimates. No hidden high-resolution interpolant is computed and treated as the truth.

Related calculations

Reading the presets

  • Quadratic — Samples of x². The global Lagrange polynomial reproduces the quadratic exactly, up to floating-point arithmetic. Piecewise Linear remains piecewise degree-1, and the Natural Cubic Spline is affected by its natural endpoint conditions — S″ = 0 at the ends, whereas (x²)″ = 2 — so it does not reproduce x² globally.
  • Sine on [0, π] — A smooth, gently curved function sampled at five points: the classic case where the spline beats the polyline and the polynomial behaves well.
  • Runge 1/(1+25x²) — Eleven equally spaced nodes on [−1, 1]. The global polynomial oscillates violently near the ends while the piecewise methods stay tame — the Runge phenomenon, visible rather than described.
  • Sensor calibration (no reference) — Six sparse, unevenly spaced calibration readings. There is no true function: the methods can only be compared with one another, and their differences are NOT error estimates.