Lagrange Interpolation Calculator

Interpolated value P(3)19.0000
Basis values L0, L1, L2 at x1.0000, -3.0000, 3.0000
Fitted quadratic2.0000x^2 + 0.0000x + 1.0000
Basis sum (check = 1)1.0000
How this was calculated
  1. Lagrange interpolation builds one basis polynomial per point that is 1 at its own node and 0 at the others, then blends the y-values with them.
  2. At x = 3 the basis values are L0 = 1.0000, L1 = -3.0000 and L2 = 3.0000 - they always sum to 1.
  3. The interpolated value is the weighted sum: 1 x 1.0000 + 3 x -3.0000 + 9 x 3.0000 = 19.0000.
  4. Expanded, the fitted quadratic is P(x) = 2.0000x^2 + 0.0000x + 1.0000, which passes exactly through all three points.

A Lagrange interpolation calculator fits a single polynomial through a set of data points by building one basis polynomial per point. Each basis polynomial equals 1 at its own node and 0 at the others, and the interpolant is the y-weighted sum of those basis polynomials. Through (0,1), (1,3) and (2,9), for example, the interpolant is P(x) = 2x^2 + 1. At x = 3 the basis values are 1, -3 and 3, giving P(3) = 19. The basis values at any x always sum to exactly 1, a built-in arithmetic check the calculator shows. Other worked cases include a quadratic x^2 - 2x + 3 through (1,2), (2,3) and (4,11), where P(3) = 6 with basis values -0.3333, 1 and 0.3333, and 2x^2 - x + 1 through (-1,4), (0,1) and (2,7), where P(1) = 2.

Lagrange interpolation is the accepted standard for this kind of calculation because it constructs the unique polynomial of lowest degree that passes through all the given points, using only the points themselves and no extra assumptions. It also makes the arithmetic transparent: the basis values sum to 1 at every x, so you can check the work directly. One caution the method itself reveals is that basis values outside the node range can grow large and alternate in sign, as with 1, -3 and 3 in the first example. Extrapolation amplifies errors, which is the practical face of the Runge phenomenon, so evaluating inside the node range is safest. This page shows the formula, step-by-step workings, worked examples and sources.

Worked examples

Points of a parabola at x = 3

(0 · 1 · 1 · 3 · 2 · 9 · 3)

Interpolated value P(3)19.0000
Basis values L0, L1, L2 at x1.0000, -3.0000, 3.0000
Fitted quadratic2.0000x^2 + 0.0000x + 1.0000
Basis sum (check = 1)1.0000

Unevenly spaced points

(1 · 2 · 2 · 3 · 4 · 11 · 3)

Interpolated value P(3)6.0000
Basis values L0, L1, L2 at x-0.3333, 1.0000, 0.3333
Fitted quadratic1.0000x^2 + -2.0000x + 3.0000
Basis sum (check = 1)1.0000

Negative node, evaluate inside

(-1 · 4 · 0 · 1 · 2 · 7 · 1)

Interpolated value P(1)2.0000
Basis values L0, L1, L2 at x-0.3333, 1.0000, 0.3333
Fitted quadratic2.0000x^2 + -1.0000x + 1.0000
Basis sum (check = 1)1.0000

Basis polynomials: one per point

Each term in a Lagrange interpolation is built from its own data point. The basis polynomial for a node equals 1 at that node and 0 at every other node, so it isolates one y-value and ignores the rest. The interpolant is then the y-weighted sum of these basis polynomials. A lagrange interpolation calculator constructs these basis polynomials for you and shows the weights it applies to each y-value.

Take the three points (0,1), (1,3) and (2,9). The basis polynomial L0 is 1 at x = 0 and 0 at x = 1 and x = 2; L1 is 1 at x = 1 and 0 at the other two; L2 is 1 at x = 2 and 0 elsewhere. Weighting each by its y-value and adding gives the interpolant P(x) = 2x^2 + 1, which passes through all three points.

Evaluating the basis polynomials at x = 3 shows how the weights behave away from the nodes. There the basis values are 1, -3 and 3. Multiplying by the y-values (1, 3 and 9) and summing gives P(3) = 19, which matches 2(3)^2 + 1. Notice that the basis values sum to 1 + (-3) + 3 = 1. That is not a coincidence: at any x, the basis values always sum to exactly 1. The calculator shows this sum-to-1 check automatically, giving you a built-in arithmetic check on every evaluation.

The same pattern appears with other data sets. Through (1,2), (2,3) and (4,11) the fitted quadratic is x^2 - 2x + 3, and P(3) = 6, with basis values -0.3333, 1 and 0.3333, which again sum to 1. Through (-1,4), (0,1) and (2,7) the quadratic is 2x^2 - x + 1, and P(1) = 2. That evaluation sits inside the node range, the safest place to evaluate.

  • L0 is 1 at x = 0 and 0 at x = 1 and x = 2.
  • L1 is 1 at x = 1 and 0 at the other two nodes.
  • L2 is 1 at x = 2 and 0 at x = 0 and x = 1.
  • At x = 3 the basis values are 1, -3 and 3; weighted by y = 1, 3 and 9 they give P(3) = 19.
  • The basis values sum to 1 at every x, and the calculator displays that check.
Basis values outside the node range can grow large and alternate in sign, as 1, -3 and 3 do in the first example. Extrapolation amplifies errors, which is the practical face of the Runge phenomenon.

The interpolated value and the fitted quadratic

Once the basis polynomials are in hand, the actual value of the interpolant is a short weighted sum. Each basis polynomial is built to equal 1 at its own node and 0 at every other node, so multiplying each one by its node's y-value and adding the results gives a curve that passes through every data point. For the points (0,1), (1,3) and (2,9), evaluating at x = 3 produces basis values of 1, -3 and 3. Combining them with the y-values gives P(3) = 1·1 + (-3)·3 + 3·9 = 1 - 9 + 27 = 19. That is the single number a lagrange interpolation calculator returns for this input, and the intermediate basis values are what make the result auditable rather than a black box.

The same three points also collapse into a compact closed form: P(x) = 2x^2 + 1. Expanding the basis sum is worth doing because it lets you check the fit directly. At x = 0, 2(0)^2 + 1 = 1, matching the first point. At x = 1, 2(1)^2 + 1 = 3, matching the second. At x = 2, 2(2)^2 + 1 = 9, matching the third. Three points determine a quadratic, so a curve that agrees at all three nodes must be the interpolant — the expansion and the basis sum are two views of the same polynomial.

The pattern repeats on other inputs. Through (1,2), (2,3) and (4,11) the fitted quadratic is x^2 - 2x + 3, and P(3) = 6, with basis values of -0.3333, 1 and 0.3333. Through (-1,4), (0,1) and (2,7) the quadratic is 2x^2 - x + 1, and P(1) = 2. That last evaluation sits inside the node range, the safest place to evaluate: the interpolant is pinned down by nearby points, so the value is reliable. Notice also that the basis values sum to exactly 1 in every case — a built-in arithmetic check the calculator shows, and a quick way to catch a mistyped node or y-value.

Outside the node range the picture changes. In the first example the basis values at x = 3 are 1, -3 and 3: they are larger than 1 and alternate in sign. Extrapolation amplifies errors, which is the practical face of the Runge phenomenon. A small mistake in a y-value, or a distant evaluation point, can swing the answer far more than it would inside the data range.

A sensible workflow follows from this. Enter the points, read the basis values, confirm they sum to 1, then combine them with the y-values to get the interpolated value. Expand to the closed form when you want a second, independent check that the curve really passes through every node, and keep evaluations inside the node range whenever the application allows it.

Check the basis values first: at any x they must sum to exactly 1. If they don't, recheck your nodes before trusting the interpolated value.

Uneven spacing and interior points

Evenly spaced data points are the easy case, but real measurements rarely arrive that way. A lagrange interpolation calculator handles uneven spacing without any change to the method, because each basis polynomial is tied to its own node rather than to a fixed step size. Take the three points (1,2), (2,3) and (4,11). The gaps between the x-values are 1 and then 2, so no uniform grid exists. Fitting a quadratic through them gives P(x) = x^2 - 2x + 3. Evaluating at x = 3, which sits between the nodes 2 and 4, the basis values are -0.3333, 1 and 0.3333, and P(3) = 6. The uneven spacing changes nothing about the procedure: one basis polynomial per point, each equal to 1 at its own node and 0 at the others, and the interpolant is the y-weighted sum of those basis polynomials.

The same quadratic can be checked at an interior point where the spacing is uneven on both sides. At x = 1, the first node itself, the arithmetic returns P(1) = 2, matching the data exactly, as it must. A second example with different geometry confirms the pattern: through (-1,4), (0,1) and (2,7) the fitted quadratic is 2x^2 - x + 1, and evaluating at x = 1 gives P(1) = 2. Here the evaluation point lies inside the node range, between -1 and 2, so the result is an interpolation rather than an extrapolation. Interior evaluation is the safest place to work, because the curve is pinned by data on both sides.

That safety is worth taking seriously. In the first example, through (0,1), (1,3) and (2,9), the interpolant is P(x) = 2x^2 + 1, and at x = 3 the basis values are 1, -3 and 3, giving P(3) = 19. Notice that x = 3 lies outside the node range 0 to 2, and the basis values have grown large and begun to alternate in sign. Extrapolation amplifies errors, which is the practical face of the Runge phenomenon. The interior points in the uneven examples carry basis values of modest size by comparison, which is why they are the safer place to evaluate.

One built-in check makes all of this easier to trust. The basis values at any x always sum to exactly 1, and the calculator shows that sum. Whether the nodes are evenly spaced, unevenly spaced, or the evaluation point sits inside or outside the range, that identity must hold. If the displayed basis values do not add to 1, something in the input or the arithmetic is wrong.

Uneven nodes are fine: through (1,2), (2,3) and (4,11) the quadratic is x^2 - 2x + 3, and P(3) = 6. Interior evaluation, as at P(1) = 2 for the nodes (-1,4), (0,1) and (2,7), is the safest place to work.

Interpolation versus extrapolation

Lagrange interpolation is exact at the nodes by construction. Each basis polynomial equals 1 at its own node and 0 at the others, and the interpolant is the y-weighted sum of those basis polynomials. That design guarantees the curve passes through every data point, but it says nothing about what happens between or beyond them. The distinction matters because a lagrange interpolation calculator will happily evaluate your polynomial at any x you type, and the numbers it returns mean very different things depending on where that x sits relative to your data.

Inside the node range, the basis values stay moderate and the result is dependable. Through (-1,4), (0,1) and (2,7) the quadratic is 2x^2 - x + 1, and at x = 1 the value is P(1) = 2. That point lies between the nodes, and it is the safest place to evaluate. The same holds for the example through (1,2), (2,3) and (4,11), where the fitted quadratic is x^2 - 2x + 3 and P(3) = 6, with basis values of -0.3333, 1 and 0.3333. Notice how modest those weights are: no single data point dominates, so small slips in the inputs produce small slips in the output.

Step outside the node range and the picture changes. Through (0,1), (1,3) and (2,9) the interpolant is P(x) = 2x^2 + 1. At x = 3, one step past the last node, the basis values are 1, -3 and 3, and they combine to give P(3) = 19. The weights have grown and their signs now alternate, so the terms partly cancel rather than reinforce one another. Push farther out and this pattern intensifies: basis values can grow large and alternate in sign, which means extrapolation amplifies errors. A small uncertainty in any y-value gets multiplied by an outsized weight, and the polynomial can swing sharply away from the trend your data actually suggests. This is the practical face of the Runge phenomenon.

One safeguard is built into the arithmetic. The basis values at any x always sum to exactly 1, and the calculator displays that sum as a check. If the weights do not add to 1, something has gone wrong in the computation. But a sum of 1 does not certify a trustworthy answer, because wildly large positive and negative weights can still add to 1 while producing an unstable result. Use the check to confirm the machinery is working, not to confirm that extrapolation is safe.

The practical rule is straightforward. Evaluate inside the range spanned by your nodes, where interpolation is well behaved and the weights stay tame. Treat any result beyond the outermost node as a guess that grows less reliable the farther you go, and read the basis values the calculator reports as your warning sign: when they are large and alternate in sign, you are extrapolating, and the answer deserves suspicion.

The basis values at any x always sum to exactly 1. The calculator shows this sum as a built-in arithmetic check, but a sum of 1 does not make an extrapolated result reliable.

FAQs

What is Lagrange interpolation?

Lagrange interpolation is a method that fits the unique polynomial through given points as a weighted sum of basis polynomials. Each basis polynomial equals 1 at its own point and 0 at the others, so the weighted sum passes exactly through every data point you supply.

What is P(3) through (0,1), (1,3), (2,9)?

P(3) is 19. The basis values at x = 3 are 1, -3 and 3, and the polynomial through those three points is 2x^2 + 1. Evaluating that polynomial at x = 3 confirms the result: 2 times 9, plus 1, equals 19.

Do the nodes need to be equally spaced?

No. Lagrange interpolation does not require equally spaced nodes. For example, the points (1,2), (2,3) and (4,11) are unevenly spaced, yet the method fits x^2 - 2x + 3 through them exactly, just as it would with evenly spaced points.

Why do the basis values sum to 1?

The basis polynomials form a partition of unity. Interpolating a constant function must return that same constant, and that requirement forces the sum of the basis values to equal 1 everywhere. This holds at every x, not only at the nodes.

Can I extrapolate with Lagrange interpolation?

You can, but basis values grow and alternate in sign outside the nodes, such as 1, -3 and 3. Because of that growth and sign change, errors amplify quickly beyond the range of your data, so extrapolated values should be treated with caution.

How many points fit a quadratic?

Three points determine a unique quadratic, since degree 2 equals points minus 1. All three worked examples on this page follow that rule, each fitting a quadratic through exactly three data points.

Sources

Related calculators

Linear Interpolation Calculator
Linear interpolation between two known points: estimate the y value at any x along the straight line joining them, with slope and position shown.
Bisection Method Calculator
Bisection method root finding for a cubic over a bracket, with the guaranteed error bound, final bracket and f(root) after a fixed number of iterations.
Taylor Series Calculator
Approximate e^x, sin, cos, ln(1 + x) or 1 / (1 - x) with a Taylor polynomial around any center, and see the exact value and the error of the truncation.