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.