Formula: Lagrange Interpolation Formula
- yAtX0Equals0: Y At X0 Equals0 (y(0))
- yAtX1Equals1: Y At X1 Equals1 (y(1))
- yAtX2Equals2: Y At X2 Equals2 (y(2))
- queryTargetX: Query Target (x*)
Interpolate y(x*) through 3 points using Lagrange basis polynomials L₀(x), L₁(x), L₂(x).
It evaluates P(x) = y₀·(x−x₁)(x−x₂)/((x₀−x₁)(x₀−x₂)) + y₁·(x−x₀)(x−x₂)/((x₁−x₀)(x₁−x₂)) + y₂·(x−x₀)(x−x₁)/((x₂−x₀)(x₂−x₁)) directly in your browser and updates three custom SVG visualizations in real time.
No, the nodes are fixed. For equally spaced data, rescale with t = (x − x₀)/h, where h is the spacing, and enter the query as t. The interpolated value needs no conversion, but divide the first divided difference by h and the second by h² to get them in your units. Unequally spaced data cannot be handled correctly here.
Because the Lagrange weight on y(0) at x* = 1.5 is negative, -0.125. Lifting the left point bends the parabola so it sags between 1 and 2. The calculator's scenarios confirm it: y(0) of 1.2 gives 6.6, the default 2 gives 6.5, and 3 gives 6.375. Each change is exactly -0.125 times the change in y(0).
Use Newton's form with the two divided differences on the result: P(x) = y₀ + f[0,1]·x + f[0,1,2]·x(x − 1). With the default 2, 2.5 and 1 that is 2 + 2.5x + x² − x, or x² + 1.5x + 2. Substitute any x into that expression and you will get the same answer the calculator gives.
It is the derivative of the parabola, P′(x) = f[0,1] + f[0,1,2]·(2x − 1), using the result's divided differences. For the default that is 2.5 + 1 × 2, which is the 4.5 shown at x = 1.5. If your data are rescaled from another spacing, divide this slope by h to put it back into your x units.
Only with caution. The weights grow quickly outside the interval: at x* = 4 they are 3, -8 and 6, so a 0.1 error in y(1) shifts P(4) by 0.8. The parabola may also not match the real function; data from 2ˣ gives P(3) = 7 against a true 8. Treat long extrapolations as rough guesses.
The three points lie on a straight line. The quadratic term vanishes and the interpolant is linear. Enter y values of 1, 2 and 3 and the calculator shows a₂ = 0, P(1.5) = 2.5, and the straight-line comparison also at 2.5. Any non-zero a₂ means the data curves, upwards if positive and downwards if negative.
The default data curve noticeably: the middle value 4.5 sits well below the halfway point between 2 and 9. The end-to-end straight line gives 7.25 at x = 1.5, while the parabola through all three points gives 6.5. The 0.75 gap is curvature. With straight data the two figures would be identical.
Yes. Each box is tied to its x position: the first is y at 0, the second y at 1, the third y at 2. Swapping two values describes a different set of points and a different parabola. When reading from a table, enter the rows in increasing x order and make sure the query is measured on the same scale.
When the table values curve, usually yes. The quadratic uses a third row to account for bending, which a straight line ignores. For tables with closely spaced, nearly linear rows the gain is small. Pick the three rows that surround your query, with the query near the middle row, to keep the error as small as possible.
No. The parabola passes exactly through all three points, so it reproduces any noise in them rather than averaging it out. A single bad reading bends the whole curve. For data with measurement error, fit a line or curve to many points by least squares, which this calculator does not do.
Those are the Lagrange basis weights at your query point. Multiply each y value by its weight and add them to get P(x*). They depend only on x*, not on the data, and always sum to 1. At the nodes one weight is 1 and the others are 0, which is why the curve passes exactly through every data point.
This interpolator always works with three data points at fixed positions: x₀ = 0, x₁ = 1 and x₂ = 2. You only type the three y values and the place x* where you want an estimate. The default data are y(0) = 2, y(1) = 4.5 and y(2) = 9, with a query at x* = 1.5.
The result is P(1.5) = 6.5. Below it the calculator lists the first divided difference f[0,1] = 2.5, the second divided difference f[0,1,2] = 1, a straight-line comparison figure of 7.25, and the slope of the curve at the query point, P′(1.5) = 4.5.
The explanation line gives the three Lagrange weights at the query point: L₀ = -0.125, L₁ = 0.75 and L₂ = 0.375. The interpolated value is just a weighted sum of the data: 2 × (-0.125) + 4.5 × 0.75 + 9 × 0.375. That is -0.25 + 3.375 + 3.375, which is 6.5.
Those weights depend only on x*, not on the y values. That is the useful idea behind the Lagrange form. Once you know where you are querying, you know exactly how much each data point counts, and you can see at a glance which point dominates the estimate.
Three points determine exactly one polynomial of degree two or less. The calculator never prints that polynomial, but you can rebuild it from the two divided differences it does show.
Newton's form writes the same curve as P(x) = y₀ + f[0,1]·(x − 0) + f[0,1,2]·(x − 0)(x − 1). With the default numbers that is 2 + 2.5x + 1·x(x − 1). Expanding gives x² + 1.5x + 2.
Check it against the data. At x = 0 it gives 2, at x = 1 it gives 1 + 1.5 + 2 = 4.5, and at x = 2 it gives 4 + 3 + 2 = 9. At x = 1.5 it gives 2.25 + 2.25 + 2 = 6.5, matching the calculator.
The second divided difference is labelled a₂ for a reason: it is the coefficient of x² in the expanded polynomial. Here a₂ = 1. Its value with these equally spaced points is (y₂ − 2y₁ + y₀)/2, which for the default is (9 − 9 + 2)/2 = 1. If a₂ is zero, the three points lie on a straight line and the interpolant is linear.
The slope line on the result follows from the expanded form: P′(x) = 2x + 1.5, so the slope at 1.5 is 4.5, as shown. For any data the same slope is P′(x) = f[0,1] + f[0,1,2]·(2x − 1). At x* = -1 it gives -0.5, which tells you the parabola's lowest point lies between -1 and 0.
A negative weight is the most surprising thing in the default result. At x* = 1.5, the weight on y(0) is -0.125. Raising y(0) actually lowers the estimate.
The calculator's two alternative scenarios show it. Lowering y(0) from 2 to 1.2 raises P(1.5) from 6.5 to 6.6. Raising y(0) to 3 lowers it to 6.375. Both changes are exactly -0.125 times the change in y(0), as the weight predicts.
Why negative? The query sits between x = 1 and x = 2, so those two points carry most of the weight, 0.75 and 0.375. The point at x = 0 bends the parabola: lifting it while holding the other two fixed tips the curve so that it sags slightly between 1 and 2. That is the curvature at work, and the divided differences move with it. With y(0) at 1.2, a₂ becomes 0.6; with y(0) at 3, a₂ becomes 1.5.
The weights always add to 1 at any x*. That is why a constant data set, say all three y values equal to 5, interpolates to exactly 5 everywhere. Checking that the weights add to 1 is a quick test that you have copied them correctly.
Nothing stops you entering a query outside the range 0 to 2. The calculator will evaluate the same parabola anywhere, but the weights change character.
At x* = 3 the default gives P(3) = 15.5, with weights 1, -3 and 3. At x* = 4 it gives 24, with weights 3, -8 and 6. Going the other way, x* = -1 gives 1.5 with weights 3, -3 and 1.
Inside the interval, the weights at 1.5 have absolute values that add up to only 1.25. At x* = 4 they add up to 17. Every error in the data is multiplied by those weights. I tested it: changing y(1) from 4.5 to 4.6, a shift of 0.1, moves P(4) from 24 down to 23.2, a shift of 0.8. Inside the interval the same change would move P(1.5) by only 0.075.
There is a second problem. Even with perfect data, a parabola fitted to three points need not follow the real function far away. Take values from y = 2ˣ, which are 1, 2 and 4 at x = 0, 1 and 2. The calculator gives P(3) = 7, but the true value is 8. The quadratic cannot keep up with exponential growth beyond its points.
Short extrapolation, a fraction of the spacing beyond the last point, is often acceptable for smooth data. Anything further should be treated as a guess and checked against a model of the underlying process.
The line labelled Straight-Line Estimate Through x=0 and x=2 answers a simple question: what would you get if you ignored the middle point? It is the straight line through the first and last points, (0, y₀) and (2, y₂), evaluated at your query x*.
For the default, that line runs from 2 to 9, so its slope is 3.5 and at x = 1.5 it gives 2 + 3.5 × 1.5 = 7.25. The parabola gives 6.5. The gap of 0.75 is the effect of curvature: this data bends upwards, so the chord from end to end sits above the curve between the points.
The line ignores y₁ completely. At x* = 1, where the data has a real point of 4.5, the line still says 5.5. Outside the interval its value drifts away entirely; at x* = -1 it gives -1.5 while the parabola gives 1.5.
Used carefully, the comparison is helpful. When the linear and quadratic values are close, the data has little curvature and either method would do. When they differ a lot, as with the default, the middle point matters and the quadratic is doing real work.
Real data seldom sits at x = 0, 1 and 2. The calculator cannot take other x positions, but if your three points are equally spaced you can map them onto its grid.
Suppose you have readings at 20, 25 and 30 degrees and want the value at 27. The spacing h is 5. Define t = (x − 20)/5, so the points become t = 0, 1, 2 and the query becomes t = 1.4. Enter the three readings as y(0), y(1), y(2) and 1.4 as x*. The interpolated value is in your original y units and needs no conversion.
Divided differences do need converting back. The calculator's f[0,1] is a change in y per unit step of t. Divide it by h to get the slope per unit of x, and divide a₂ by h² for the curvature coefficient in x. The same goes for any derivative you calculate.
If your three x values are not equally spaced, for example 0, 1 and 3, this mapping does not work. You would need the general formula shown on the page with your own x values, which the calculator does not let you enter. Forcing unequal data onto the 0, 1, 2 grid gives a wrong answer with no warning.
If your data come from a smooth function f, the error of a three-point quadratic at x* is f‴(ξ)/6 × (x* − 0)(x* − 1)(x* − 2), where ξ is some point in the range covered by the nodes and x*. You rarely know f‴, but the product of the three brackets tells you how risky a query is.
At x* = 1.5 that product is 1.5 × 0.5 × (-0.5), or -0.375. At x* = 0.5 it is +0.375. At any of the nodes it is zero, which is why P matches the data exactly there: the default query at x* = 2 returns 9.
Outside the interval the product grows fast. At x* = 4 it is 4 × 3 × 2 = 24, sixty-four times larger than at 1.5. Combined with the weight growth described above, that is the full case against long extrapolation.
The 2ˣ example puts real numbers on it. With data 1, 2 and 4, the calculator gives P(1.5) = 2.875, while the true value of 2 to the power 1.5 is about 2.828. That error, under 2%, is typical of a smooth function sampled closely enough. The error at x = 3 is larger, a full unit out of 8.
Three-point quadratics are a standard tool for reading between rows of a table: steam tables, thermocouple tables, survival tables, or any published values at regular steps. Linear interpolation is fine when the rows are close and the data nearly straight. A quadratic is worth the extra effort when the table visibly curves.
Choose the three rows that surround your query, ideally with the query near the middle row. Use rows 1, 2 and 3 to estimate a value between 1.5 and 2.5, rather than rows 0, 1 and 2 with the query near the end.
It is also the basis of simple peak finding. If three equally spaced samples bracket a maximum, the vertex of the parabola through them estimates the true peak. With this calculator's grid the vertex is at x = 0.5 − f[0,1]/(2a₂), using the result's two divided differences.
The method is not a fit to noisy data. The parabola passes exactly through all three points, so any measurement noise is copied into the curve. For scattered data with errors, a least-squares fit over more points is the better tool.