Lagrange Interpolation Calculator
Build the unique polynomial through three data points using Lagrange interpolation.
Enter x and y coordinates, then evaluate the polynomial at any x value.
Lagrange interpolation finds the unique polynomial of degree n-1 that passes exactly through n given data points. For three points, it finds a quadratic (degree 2) polynomial.
The formula for three points (x0,y0), (x1,y1), (x2,y2):
L(x) = y0 x (x-x1)(x-x2) / ((x0-x1)(x0-x2)) + y1 x (x-x0)(x-x2) / ((x1-x0)(x1-x2)) + y2 x (x-x0)(x-x1) / ((x2-x0)(x2-x1))
Each of the three terms is called a Lagrange basis polynomial. At x = x0, only the first term is nonzero and equals y0. The same applies to each point. This guarantees the polynomial passes through all given points.
When to use it. Lagrange interpolation is useful when you have a small number of exactly known data points and need to estimate the value between them. It appears in numerical integration (Simpson’s rule uses it), computer graphics for smooth curves, and scientific data fitting.
Watch out for Runge’s phenomenon. With many equally spaced points, high-degree Lagrange polynomials develop wild oscillations near the edges of the interval. For more than 5-6 points, spline interpolation is usually preferred.
Extrapolation is risky. Evaluating L(x) far outside the range of your data points can give wildly inaccurate results. The chart below shows the polynomial over the range of your points. The curve outside that range should be treated with skepticism.
The three x-values must all be distinct. Two points sharing the same x causes a division by zero in the formula.
A small note on the name. Joseph-Louis Lagrange published this formulation in 1795, but Edward Waring had derived essentially the same construction in 1779, sixteen years earlier. The name stuck to Lagrange. That sort of misattribution is common enough in mathematics that it has a name of its own: Stigler’s law of eponymy.
One unexpected modern use — secret sharing. Adi Shamir’s threshold cryptography scheme (1979) is built directly on this formula. To split a secret S among n people so that any k of them can recover it, you construct a degree-(k−1) polynomial whose constant term is S, hand each person a point on the curve, and reconstruct S by Lagrange-interpolating to find the value at x = 0. Cryptocurrency wallets and bank key-management systems use this every day.
How we build and check this calculator
This calculator runs entirely in your browser, so the numbers you enter stay on your device. The math behind it is written by hand and tested against worked examples and standard references before the page goes live.
SuperGlobalCalculator is independently built and maintained. See how we build and verify our calculators.