Interpolation Calculator
Read a value between data points — by straight line, or by the polynomial through every point, with the divided-difference table.
3 points, so the interpolating polynomial has degree 2. The polynomial passes through every one of them exactly.
degree 2 polynomial through all 3 points
one less than the number of points, unless the data already lies on something simpler
difference 1.068e-3
x from 1.95y from 0.67 to 0.86to 2.35
P(x) = −0.10678x^2 + 0.925027x − 0.729787
| x | f(x) | order 1 | order 2 |
|---|---|---|---|
| 2 | 0.6931472 | 0.476551 | -0.10678 |
| 2.2 | 0.7884574 | 0.444517 | |
| 2.3 | 0.8329091 |
The highlighted top row is the Newton form’s coefficients: P(x) = f[x₀] + f[x₀,x₁](x − x₀) + f[x₀,x₁,x₂](x − x₀)(x − x₁) + …
Linear interpolation reads between two table rows: y = y₀ + (x − x₀)(y₁ − y₀) ÷ (x₁ − x₀). Polynomial interpolation uses every point instead, and exactly one polynomial of degree ≤ n passes through n + 1 points with distinct x values.
Between two rows of a table
The everyday case is a printed table that stops short of the value you need — a steam table at 110 °C and 120 °C when the problem says 115 °C, a tax band, a calibration curve. Linear interpolation draws a straight line between the two neighbouring rows and reads off the height at your x. It is the first thing to reach for, it needs no more than four numbers, and for a smooth quantity sampled closely it is usually accurate enough that the table’s own rounding dominates the error.
The accuracy has a known shape. The error of linear interpolation over a step of width h is bounded by h²·max|f″| ÷ 8, so halving the spacing quarters the error. That is also why a table with tight rows can be interpolated linearly with confidence while one with wide rows cannot.
Using every point at once
Polynomial interpolation fits a single polynomial through all the data. There is exactly one of degree at most n through n + 1 points with distinct x values, so Lagrange’s formula and Newton’s divided-difference formula are not competing answers — they are two ways of writing the same polynomial, and this page computes both and checks them against each other.
Newton’s form is the one worth seeing, because the divided differences build up in a triangle that a textbook will ask you to reproduce. Each entry divides a difference of the column to its left by the span of x it covers, and the top row of the triangle is exactly the list of coefficients. Adding a new data point appends one row and one new coefficient without disturbing anything already computed, which is why Newton’s form is preferred in practice over Lagrange’s.
Newton’s divided-difference form; the coefficients are the top row of the triangle
- 1 Sort the points by x. Interpolation does not care about the order they were collected in, but the table is only readable sorted.
- 2 For a straight line, find the two points either side. Then y = y₀ + (x − x₀) × (y₁ − y₀) ÷ (x₁ − x₀). The fraction is the slope of the segment.
- 3 For a polynomial, build the divided-difference table. First column is the y values. Each later entry is the difference of the two above it, divided by the span of x those entries cover.
- 4 Read the coefficients off the top row. They multiply 1, (x − x₀), (x − x₀)(x − x₁) and so on, in that order.
- 5 Evaluate by nesting, not by expanding. Expanding to standard form loses precision when the x values are large or close together; nested evaluation does not.
Which method for which job
Degree here means the degree of the polynomial actually fitted, not the number of points available.
| Situation | Use | Why |
|---|---|---|
| Reading between two table rows | Linear | Error falls with the square of the row spacing; a close table needs nothing more. |
| Three to five well-spaced points | Polynomial | Captures curvature the straight line misses, without room to oscillate. |
| Many points, evenly spaced | Splines, not a single polynomial | A high-degree fit on even spacing swings wildly between the data — Runge’s phenomenon. |
| Many points, noisy | Least-squares regression | Interpolation passes through every point, including the errors in them. |
| Outside the data range | Nothing, if you can avoid it | Every method above is unreliable there, and the polynomial is the worst of them. |
Why more points can make the answer worse
It is natural to assume that fitting more points gives a better curve. For evenly spaced data it is false, and spectacularly so. The standard demonstration is Runge’s function, 1 ÷ (1 + 25x²), on the interval from −1 to 1. Interpolating it at 5 evenly spaced points gives a worst error of about 0.44. At 9 points the worst error is about 1.05; at 11 points, 1.92; at 15 points, 7.19. The polynomial passes through every data point exactly and is wrong by more than the function’s entire range in between, with the damage concentrated near the ends.
The fix is not a better algorithm but a different model: either put the points where the oscillation cannot grow — Chebyshev spacing, clustered towards the ends — or give up on one global polynomial and join low-degree pieces instead, which is what a spline does. Both are standard, and both exist because the single high-degree interpolant does not work.
One more limit worth stating plainly. Interpolation reconstructs a function between points you trust. If the data carry measurement error, forcing a curve through every point forces it through every error too, and a regression line that misses all the points can easily be the more accurate model. Extrapolating past the ends of the data is worse again: the tool marks it, because a polynomial’s behaviour outside its data is governed by its highest-degree term and has nothing to do with the phenomenon you measured.