BL2.ru

Interpolation - Lagrange polynomial (online calculator)

Lagrange interpolation polynomial through arbitrary points: add as many nodes (x; F(x)) as needed and the point xn. You get basis values Lx, the result, the explicit polynomial and a graph.

Calculate
Here you can interpolate using the Lagrange formula online. You can also use the services Linear interpolation and extrapolation, Bilinear interpolation and Newton polynomial.

Lagrange interpolation polynomial

L(x) = Σi=1..n Fxi · Lxi,   Lxi = Πj≠i (x − xj) / (xi − xj)

What the calculator does

You have a table of known values: at points x1, x2, …, xn the function equals Fx1, Fx2, …, Fxn, but its formula is unknown. The Lagrange polynomial is the unique polynomial of degree at most n−1 that passes exactly through all these points. The calculator builds it and evaluates it at the point xn you need.

How the formula works

For each point a basis factor Lxi is built: it equals 1 at its "own" point xi and 0 at every other node.

Lxi = Πj≠i (x − xj) / (xi − xj)

The answer is the sum of the values weighted by these factors: L(x) = Σ Fxi · Lxi. The calculator shows every Lxi so you can see each point's contribution; they always add up to 1.

Example

Known: f(1) = 1, f(2) = 4, f(4) = 16 (this is y = x², but the calculator doesn't need to know that). Find f(3):

ixiFxiLxi(3)Fxi · Lxi
111(3−2)(3−4) / ((1−2)(1−4)) = −1/3−1/3
224(3−1)(3−4) / ((2−1)(2−4)) = 14
3416(3−1)(3−2) / ((4−1)(4−2)) = 1/316/3

Sum: −1/3 + 4 + 16/3 = 9. Exactly 3² — a quadratic is recovered exactly from three points.

Good to know

  • Nodes can have any spacing — unlike the Newton formulas on this site, which need an equal step. The xi just must not repeat.
  • Accuracy. If the function is a polynomial of degree lower than the number of points, the result is exact. For other functions it is an approximation, best between the nodes.
  • Extrapolation (a point outside the node range) works, but the error grows quickly.
  • More points are not always better. With 10–20 equally spaced nodes the polynomial starts to oscillate near the ends (Runge's phenomenon). For large tables, use the 3–5 nearest points or splines.
  • Versus Newton. It is the same polynomial. The Lagrange form is easier to write and understand; the Newton form is handier when points are added one by one, since nothing has to be recomputed from scratch.

Where it is used

  • Measurement tables and handbooks — a value between sensor calibration points, material properties, tabulated coefficients, when 3–4 points are known and the dependence is non-linear.
  • Numerical methods — numerical integration (Newton–Cotes, Simpson's rule) and numerical differentiation formulas are built on the Lagrange polynomial.
  • Computer graphics and animation — a smooth curve through given key points.
  • Signal processing — resampling and fractional delay (Lagrange interpolation filters in audio).
  • Cryptography — Shamir's secret sharing: the secret is recovered by Lagrange interpolation from several shares.
  • Studying — check numerical-methods homework and see each point's contribution.

How to use

  • Enter pairs xi and Fxi; add a row with "+", remove one with "−".
  • Put the point you need into xn and press "Calculate". With the box inside the button ticked, it recalculates on every change.
  • Fractions (1/3), decimal commas (0,5) and expressions work, as in the other calculators of this section.

FAQ

How many points can I use?
Any number from two, but high-degree polynomials oscillate (Runge’s phenomenon). For long tables a cubic spline is better.
Do x values need equal spacing?
No, any spacing works; x values must not repeat.
How do I get the polynomial itself?
P(x) is shown below the buttons in standard and Lagrange form, together with a graph.
How is it different from curve fitting?
Lagrange passes exactly through every point. For noisy data use least squares curve fitting.