The guide
One polynomial passes through your points, and more points do not always make it better
Exactly one lowest-degree polynomial passes through n points with different x values. Lagrange and Newton write it two ways, and equal spacing can make it swing wildly.
- 223/10560 x cubed coefficient for the four-point example
- -2587/880 value at x = 0 for the same four points
- 1.9156 largest error, 11 equal nodes on the Runge function
- 0.1092 largest error, 11 Chebyshev nodes
Read the full guide Fold the guide
Give me two points and there is exactly one straight line through them. Give me three points with different x values and there is exactly one parabola, or a line if the points happen to sit on one. The pattern keeps going, and it is more rigid than most people expect. The rule is this. Take n points whose x values are all different. Among polynomials of degree at most n minus 1, exactly one passes through every point. Not several, not none. That polynomial is called the interpolating polynomial, and the Lagrange form is the oldest way to write it down.
Why there is only one
Suppose two different polynomials of degree at most n minus 1 both went through your n points. Subtract one from the other. The difference is also a polynomial of degree at most n minus 1, and it is zero at all n x values. But a nonzero polynomial of that degree has at most n minus 1 roots, so the difference cannot be anything except zero. The two polynomials were the same all along.
That argument is short, and it carries the whole subject. It also explains why the x values must differ. Two points with the same x and different y cannot lie on any function of x at all, and two with the same x and the same y are one point counted twice.
There is a second way to see it. Writing the polynomial as a sum of powers of x turns the problem into a set of linear equations whose matrix is a Vandermonde matrix. Its determinant is the product of all the differences between x values, so it is zero exactly when two x values coincide. Different x values mean an invertible matrix, and an invertible matrix means one answer.
Lagrange’s way: terms that switch on and off
Solving those equations directly works, but it hides the structure. Lagrange’s form builds the answer from pieces. For each point, write a basis polynomial that equals 1 at that point’s x and 0 at every other x. Multiply each one by its y, and add them up.
How do you build a polynomial that is 1 at one place and 0 at the others? Put the zeros in by hand. If the other x values are a, b and c, then the product of (x minus a), (x minus b) and (x minus c) is zero at all three. Divide by its own value at the chosen x, and it becomes exactly 1 there. Each term is therefore y times a product, over a denominator that is a plain number.
A small example makes it concrete. Take the four points (-9, 5), (-4, 2), (-1, -2) and (7, 9). For the first point the other x values are -4, -1 and 7. The denominator is (-9 + 4)(-9 + 1)(-9 - 7), which is -640, so the first term is 5 times (x + 4)(x + 1)(x - 7) over -640, a weight of -1/128 on the product. The other three weights are 2/165, 1/96 and 9/1408.
Add the four terms and expand. The result has degree 3, with coefficients 223/10560, 359/1760, -7993/10560 and -2587/880 from the highest power down. At x = 0 it returns -2587/880, about -2.94. At each of the four given x values it returns the given y, which is the whole point. Try it in the calculator above and the same fractions appear.
The history is a little tangled. The form carries Lagrange’s name and he published it in 1795, but Edward Waring had found it in 1779, and it follows easily from a formula Euler published in 1783. Names in mathematics often record who was last to say a thing loudly.
Newton’s way: one point at a time
The Lagrange form has a practical flaw. Add one more point and every basis polynomial changes, so you start over. Newton’s form avoids this by building the polynomial in steps. It starts with a constant, adds a term that fixes the second point without disturbing the first, adds a term that fixes the third without disturbing the first two, and so on.
The coefficients come from divided differences. The first column is just the y values. Each later entry is the difference of two neighbours in the previous column, divided by the difference of the x values at the ends of the span they cover. For the four points above, the top row of that table reads 5, -3/5, -11/120 and 223/10560.
The polynomial is then 5, plus -3/5 times (x + 9), plus -11/120 times (x + 9)(x + 4), plus 223/10560 times (x + 9)(x + 4)(x + 1). Expand it and you get the same cubic as before, coefficient for coefficient. The last divided difference, 223/10560, is also the leading coefficient, which is why it matches the first number in the Lagrange expansion.
Two forms, one polynomial. That is not a coincidence or a rule of thumb; it follows from the uniqueness argument above. The calculator expands both forms independently and compares the results, so a slip in either one would show as a mismatch rather than a quietly wrong answer.
Why exact fractions matter
A common mistake is to round early. Evaluating the Lagrange form at a point close to one of the nodes subtracts two nearly equal numbers, the situation known as catastrophic cancellation, and rounded intermediate figures make it worse. A coefficient that looks like 0.0211 in a hurried hand calculation is really 223/10560, and the gap matters when you evaluate far from the data.
Computers have a version of the same trap. Binary floating point cannot store 0.1 exactly, and the Python documentation points out that asking for a fraction from the float 1.1 does not give 11/10. A typed decimal, though, is a statement about a decimal number, and it can be turned into a fraction exactly: 1.1 is 11/10, full stop.
So the tool reads your numbers as exact fractions using whole numbers too large for ordinary floating point, which JavaScript provides as BigInt. The cost is that numbers can grow. Thirty points with long fractions produce coefficients thousands of digits long, so the calculator caps the input and does the heavy work in a background worker, which keeps the page responsive while it runs.
When more points make things worse
It is natural to think that more points give a better curve. Often the opposite happens. Carl Runge found that if you take the function 1 divided by (1 + 25 times x squared) and interpolate it at equally spaced points between -1 and 1, the polynomial through more points swings harder near the ends of the interval. Raising the degree does not shrink the error. It can blow it up.
You can measure it. With 11 equally spaced nodes the largest gap between the polynomial and the true function, checked on a grid of 4,001 values, is about 1.9156. That is larger than the function’s own maximum of 1. The polynomial is exact at the 11 nodes and wrong by nearly twice the height of the thing it was supposed to follow in between.
Two things combine to cause this. The derivatives of this particular function grow quickly with order, and equal spacing makes a quantity called the Lebesgue constant, which compares the interpolant with the best polynomial approximation and bounds its error, grow exponentially with the number of nodes. Neither alone produces the effect as dramatically; together they do.
The cure is to stop spacing the nodes evenly. Chebyshev nodes, cos((2k + 1) pi / (2n)) for k from 0 to n minus 1, crowd toward the ends of the interval, where the polynomial needs the most restraint. With 11 of them the same largest error drops to about 0.1092, about 17.5 times smaller. The Lebesgue constant for these nodes grows only like the logarithm of n.
Interpolating is not fitting
None of this makes interpolation a good model for measured data. A polynomial forced through every point must pass through the noise too, and with many points it will wiggle between them. This is overfitting in its plainest form: when a model has as many free parameters as there are observations, it can reproduce the data perfectly by memorising it, and it typically predicts new values badly.
Use interpolation when the points are exact, or close enough to exact, and you want a smooth curve between them: values from a table, results of a calculation, samples you trust. Use a fit, such as least squares with a low degree, when the points are noisy and you want the trend. A line through a cloud of points ignores the noise. A degree-8 interpolant memorises it.
Be careful with values outside the data. The polynomial is perfectly defined there, and the calculator will give you an exact number, but exact is not the same as accurate. Past the last point a polynomial can head off in its own direction, and nothing in the method promises it follows the real curve. Treat extrapolation as a guess with good arithmetic.
Finally, notice how many unrelated places use the same idea. Lagrange polynomials appear in numerical integration formulas, in a scheme for splitting a secret into shares, and in error-correcting codes. The thread through all of them is the rigidity this essay began with: enough points pin down one polynomial, and then everything else is arithmetic.
Sources
Every source consulted for this guide. Links checked November 10, 2026.
- Lagrange polynomial Wikipedia
- Newton polynomial Wikipedia
- Divided differences Wikipedia
- Polynomial interpolation Wikipedia
- Vandermonde matrix Wikipedia
- Runge's phenomenon Wikipedia
- Chebyshev nodes Wikipedia
- Lebesgue constant Wikipedia
- Overfitting Wikipedia
- DLMF: Section 3.3 Interpolation, Chapter 3 Numerical Methods NIST Digital Library of Mathematical Functions
- fractions - Rational numbers Python Software Foundation
- BigInt MDN Web Docs
- Web Workers API MDN Web Docs