What is the linear interpolation?
Type two known points and an x value to read the value in between. Leave any one of the six boxes empty and it is filled in from the other five.
- y
- 6.5
The line through (2, 4) and (3, 9) passes through (2.5, 6.5).
y: 6.5. The line through (2, 4) and (3, 9) passes through (2.5, 6.5).
How to calculate
Finds a value between (or beyond) two known points by linear interpolation, y = y₁ + (x − x₁)(y₂ − y₁) ÷ (x₂ − x₁), or any one of the six numbers from the other five.
Example with the default inputs (x₁ 2, y₁ 4, x₂ 3, y₂ 9, x 2.5): The line through (2, 4) and (3, 9) passes through (2.5, 6.5).
Formula: y = y₁ + (x − x₁)(y₂ − y₁) ÷ (x₂ − x₁): the straight line through (x₁, y₁) and (x₂, y₂), read at x.
- The value changes along a straight line between the two known points (linear interpolation).
- An x outside x₁ to x₂ gives an extrapolated value along the same line.
- Each number typed is between −10¹² and 10¹².
- Solving for any other number uses the same line through the two points that are fully known. There is no answer when those two points share an x value (or, reading x from y, a y value).
Worked examples
Each example is checked against the calculator on every build.
- x₁ 2, y₁ 4, x₂ 3, y₂ 9, x 2.5 gives y 6.5.Source: hand calculation in content.mdx: 4 + (2.5 − 2)(9 − 4) ÷ (3 − 2) = 6.5
- x₁ 2, y₁ 4, x₂ 3, y₂ 9, x 4 gives y 14.Source: hand calculation in content.mdx: 4 + (4 − 2) × 5 ÷ 1 = 14 (extrapolation beyond x₂)
- x₁ 2, y₁ 4, x₂ 3, y₂ 9, y 6 gives x 2.4.Source: hand calculation in content.mdx: x = 2 + (6 − 4)(3 − 2) ÷ (9 − 4) = 2.4
- x₁ -1, y₁ 5, x₂ 4, y₂ -5, x 0 gives y 3.Source: hand calculation in content.mdx: 5 + (0 + 1)(−5 − 5) ÷ (4 + 1) = 5 − 2 = 3
- x₁ 0, y₁ 0, x₂ 10, x 4, y 2 gives y₂ 5.Source: hand calculation in content.mdx: the line through (0, 0) and (4, 2) has slope 0.5, so at x = 10, y₂ = 5
How it works
Linear interpolation draws the straight line through two known points, (x₁, y₁) and (x₂, y₂), and reads it at a third point (x, y):
y = y₁ + (x − x₁)(y₂ − y₁) ÷ (x₂ − x₁)
This is the point-slope form of a line, y − y₁ = m(x − x₁), with slope m = (y₂ − y₁) ÷ (x₂ − x₁). It is also the Lagrange interpolation polynomial for two points.
Type any five of the six numbers. The calculator finds the sixth by drawing the line through the two points it knows fully and reading it at the known coordinate of the third:
- y from x: y = y₁ + (x − x₁)(y₂ − y₁) ÷ (x₂ − x₁)
- x from y: x = x₁ + (y − y₁)(x₂ − x₁) ÷ (y₂ − y₁)
- y₂ from the others: y₂ = y₁ + (x₂ − x₁)(y − y₁) ÷ (x − x₁), the line through (x₁, y₁) and (x, y) read at x₂
- y₁ from the others: y₁ = y₂ + (x₁ − x₂)(y − y₂) ÷ (x − x₂)
- x₂ from the others: x₂ = x₁ + (y₂ − y₁)(x − x₁) ÷ (y − y₁)
- x₁ from the others: x₁ = x₂ + (y₁ − y₂)(x − x₂) ÷ (y − y₂)
Assumptions
- The values change along a straight line between the two points.
- An x outside the range x₁ to x₂ gives an extrapolated value on the same line.
- There is no answer when the formula would divide by 0: the two fully known points share an x value (or, when finding an x, a y value).
- Each number typed is between −10¹² and 10¹².
- x₁ must differ from x₂ also when either one is the value being solved: if the solved x₁ or x₂ comes out equal to the other (for example y₁ = y₂ with x₁ solved), the two points share an x value and there is no answer.
- When x₁ = x₂, the page gives no answer and says: "x₁ and x₂ must be different: two points with the same x make no line to read y from."
- When x is solved and y₁ = y₂ (a flat line), the page gives no answer and says: "y₁ and y₂ must be different to find x: the line is flat, so every x has the same y."
Worked examples by hand
Halfway between (2, 4) and (3, 9). The rise is 9 − 4 = 5 over a run of 3 − 2 = 1. At x = 2.5, y = 4 + (2.5 − 2) × 5 ÷ 1 = 4 + 2.5 = 6.5.
The same line at x = 4. y = 4 + (4 − 2) × 5 ÷ 1 = 14. This is extrapolation, beyond x₂ = 3.
The same line at y = 6. x = 2 + (6 − 4) × (3 − 2) ÷ (9 − 4) = 2 + 2 ÷ 5 = 2.4.
Between (−1, 5) and (4, −5) at x = 0. y = 5 + (0 − (−1)) × (−5 − 5) ÷ (4 − (−1)) = 5 + 1 × (−10) ÷ 5 = 3.
Find y₂ at x₂ = 10 on the line through (0, 0) and (4, 2). The slope is 2 ÷ 4 = 0.5, so y₂ = 0 + 0.5 × (10 − 0) = 5.
Other questions people ask
What is linear interpolation?
It estimates a value between two known points by assuming a straight line joins them. If a table gives 4 at x = 2 and 9 at x = 3, linear interpolation says the value at x = 2.5 is halfway between: 6.5.
What is the linear interpolation formula?
y = y₁ + (x − x₁)(y₂ − y₁) ÷ (x₂ − x₁). The fraction (x − x₁) ÷ (x₂ − x₁) says how far x is along the way from x₁ to x₂, and that share of the rise y₂ − y₁ is added to y₁.
How do I interpolate backwards, to find x from y?
Swap the roles of x and y: x = x₁ + (y − y₁)(x₂ − x₁) ÷ (y₂ − y₁). Type y and leave x empty, and the calculator does this. Between (2, 4) and (3, 9), y = 6 is at x = 2.4.
What is the difference between interpolation and extrapolation?
Interpolation reads the line between the two known points. Extrapolation reads it beyond them, such as x = 4 from points at x = 2 and x = 3. The formula is the same, but extrapolated values are less reliable, because the data may stop following a straight line.
How accurate is linear interpolation?
It is exact when the data really lie on a straight line and close when the points are near each other. For a curve it is off: between (2, 4) and (3, 9) on y = x², it gives 6.5 at x = 2.5, but 2.5² = 6.25. Points closer together give a smaller error.
Why is there no answer when x₁ equals x₂?
Two points with the same x lie on a vertical line, which has no single y for other values of x. The formula would divide by x₂ − x₁ = 0.