Lagrange Interpolation Polynomial Calculator

Enter your x,y data points and an x value to evaluate the Lagrange interpolating polynomial.

Result

5.8750
3
4

How it is calculated

Enter one point per line as x,y (a comma or a space both work) and a query value xq. With n points (xi, yi) the tool evaluates P(xq) = Σ yi · Πj≠i (xq − xj) / (xi − xj). It does not print the polynomial's coefficients, only the value at xq, plus the number of points used and the degree n − 1, which is the highest degree the polynomial can have. Every non-empty line must hold exactly two numbers: a line with one number, three numbers or text makes the whole input invalid and no result is shown. Two points with the same x also give no result, because the denominator would be zero, and at least two points are needed. Asking for an xq outside your data range is extrapolation and can be wildly off.

Worked example

Use the four points (0, 1), (1, 3), (2, 11), (3, 31) and ask for xq = 1.5. The weights at 1.5 are −0.0625, 0.5625, 0.5625 and −0.0625, one per point. Multiplying by the y values gives −0.0625 + 1.6875 + 6.1875 − 1.9375. The sum is 5.8750, and the tool reports 4 points and degree 3. These points happen to lie on x³ + x + 1, so 1.5³ + 1.5 + 1 gives the same figure.

Try this example →

Common mistakes

  • Repeating an x value, for example two measurements at the same x. The tool returns nothing, because a function cannot have two different y values at one x. Average them or drop one first.
  • Extrapolating. With four points, asking for a value far outside their x range gives a large, unreliable number: for xq = 10 these same points give 1,011.0000.
  • Using a decimal comma inside a point line. A line such as 1,5 is read as x = 1 and y = 5, not x = 1.5, and 1,5 2 has three numbers and is rejected. Write decimals with a dot.
  • Leaving a stray line, such as a header or a note, in the list. It is not skipped: the whole input is rejected, so remove everything except the x,y lines.
  • Using noisy measurements with many points. The polynomial passes exactly through every point, noise included, so it can oscillate; a regression fit suits noisy data better.

About this calculator

Lagrange interpolation constructs the unique lowest-degree polynomial that passes exactly through a given set of (x, y) points, built as a weighted sum of "basis" polynomials — each one designed to equal 1 at its own x-value and 0 at every other data point's x-value. Unlike fitting a line or curve by least-squares regression, which minimizes overall error but generally misses most points, Lagrange interpolation guarantees the polynomial threads through every single point exactly, which is exactly what you want when the data points are trusted, exact values rather than noisy measurements.

This calculator takes your set of x,y data points (one per line, with distinct x values) and evaluates the Lagrange polynomial at any x value you choose, showing the interpolated value, the number of points and the polynomial degree. It does not print the polynomial's coefficients or expression. Numerical methods students verifying interpolation by hand, engineers estimating a value between sparse tabulated data (like steam tables or lookup charts), and programmers implementing curve-fitting from scratch use it to check their derivations or quickly get an interpolated estimate without coding the algorithm themselves.

Was this helpful?

You can pick up to 3 reactions.

Comments

  • Be the first to comment.

Popular calculators

All Calculators