What is the linear interpolation at x?
Type two known points and the x you want. The linear interpolation calculator reads the straight line between them at x and shows the slope and each step.
- y at x
- 6.5
The line through (2, 4) and (3, 9) gives y = 6.5 at x = 2.5.
- Slope m
- 5
- Position t
- 0.5
- Interpolation or extrapolation
- Interpolation: x is between x₁ and x₂
- Steps
- m = (y₂ − y₁) ÷ (x₂ − x₁) = (9 − 4) ÷ (3 − 2) = 5; y = y₁ + m × (x − x₁) = 4 + 5 × (2.5 − 2) = 6.5
y at x: 6.5. The line through (2, 4) and (3, 9) gives y = 6.5 at x = 2.5.
How is y worked out?
How to calculate
Finds y at x on the straight line through two points, y = y₁ + (x − x₁)(y₂ − y₁) ÷ (x₂ − x₁), with the slope and every step.
Example with the default inputs (x₁ 2, y₁ 4, x₂ 3, y₂ 9, x 2.5): The line through (2, 4) and (3, 9) gives y = 6.5 at x = 2.5.
Method: m = (y₂ − y₁) ÷ (x₂ − x₁); y = y₁ + m (x − x₁). Worked in exact fractions of the typed decimals, rounded once.
- The value changes along a straight line between the two known points.
- An x outside x₁ to x₂ gives an extrapolated value along the same line.
- Each number is from −10¹² to 10¹². x₁ and x₂ must differ.
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 at x 6.5, Slope m 5, Position t 0.5, Interpolation or extrapolation Interpolation: x is between x₁ and x₂.Source: OpenStax, College Algebra 2e, §4.1 Linear Functions (slope m = (y₂ − y₁) ÷ (x₂ − x₁) and point-slope form y − y₁ = m(x − x₁)), https://openstax.org/books/college-algebra-2e/pages/4-1-linear-functions
- x₁ 2, y₁ 4, x₂ 3, y₂ 9, x 4 gives y at x 14, Position t 2, Interpolation or extrapolation Extrapolation: x is outside x₁ to x₂.Source: OpenStax, College Algebra 2e, §4.1 Linear Functions (slope m = (y₂ − y₁) ÷ (x₂ − x₁) and point-slope form y − y₁ = m(x − x₁)), https://openstax.org/books/college-algebra-2e/pages/4-1-linear-functions
- x₁ 0.1, y₁ 0.2, x₂ 0.3, y₂ 0.4, x 0.2 gives y at x 0.3, Slope m 1, Position t 0.5.Source: OpenStax, College Algebra 2e, §4.1 Linear Functions (slope m = (y₂ − y₁) ÷ (x₂ − x₁) and point-slope form y − y₁ = m(x − x₁)), https://openstax.org/books/college-algebra-2e/pages/4-1-linear-functions
- x₁ 20, y₁ 2.339, x₂ 25, y₂ 3.169, x 22 gives y at x 2.671, Slope m 0.166, Position t 0.4.Source: OpenStax, College Algebra 2e, §4.1 Linear Functions (slope m = (y₂ − y₁) ÷ (x₂ − x₁) and point-slope form y − y₁ = m(x − x₁)), https://openstax.org/books/college-algebra-2e/pages/4-1-linear-functions
- x₁ -1, y₁ 5, x₂ 4, y₂ -5, x 0 gives y at x 3, Slope m -2.Source: OpenStax, College Algebra 2e, §4.1 Linear Functions (slope m = (y₂ − y₁) ÷ (x₂ − x₁) and point-slope form y − y₁ = m(x − x₁)), https://openstax.org/books/college-algebra-2e/pages/4-1-linear-functions
How it works
Linear interpolation draws the straight line through two known points (x₁, y₁) and (x₂, y₂) and reads it at x:
- Slope: m = (y₂ − y₁) ÷ (x₂ − x₁)
- Position: t = (x − x₁) ÷ (x₂ − x₁)
- Value: y = y₁ + m (x − x₁) = y₁ + t (y₂ − y₁)
The result is interpolation when x₁ ≤ x ≤ x₂ (or x₂ ≤ x ≤ x₁), that is 0 ≤ t ≤ 1, and extrapolation otherwise. There is no answer when x₁ = x₂, with the message that the two x values must differ. There is also no answer, with a message, when x₁ and x₂ are so close that the slope, t or y is beyond the largest 64-bit number (about 1.8 × 10³⁰⁸).
Exact arithmetic. Each typed number is read as the exact decimal it shows (0.1 is exactly 1/10). m, t and y are worked out in exact fractions and rounded once at the end, so 0.2 + 1 × 0.1 gives 0.3, not 0.30000000000000004.
Output format. y, m and t show as decimal numbers, rounded half up from their exact values. "Interpolation or extrapolation" shows as text. The steps show the slope, then y. Each number in them is its exact value rounded half up to 12 significant digits, written in the shortest form (trailing zeros dropped; an exponent such as 1e+21 from 10²¹ up or below 10⁻⁶), with negative numbers in brackets.
Assumptions
- The value changes along a straight line between the two points.
- Each number is from −10¹² to 10¹².
Worked examples by hand
(2, 4) and (3, 9) at x = 2.5. m = (9 − 4) ÷ (3 − 2) = 5; t = 0.5 ÷ 1 = 0.5; y = 4 + 5 × 0.5 = 6.5. Interpolation.
The same points at x = 4. t = 2, so y = 4 + 5 × 2 = 14. Extrapolation.
(0.1, 0.2) and (0.3, 0.4) at x = 0.2. m = 0.2 ÷ 0.2 = 1; y = 0.2 + 1 × 0.1 = 0.3 exactly; t = 0.5.
Between two table rows: (20, 2.339) and (25, 3.169) at x = 22. m = 0.83 ÷ 5 = 0.166; t = 2 ÷ 5 = 0.4; y = 2.339 + 0.166 × 2 = 2.671.
(−1, 5) and (4, −5) at x = 0. m = −10 ÷ 5 = −2; y = 5 + (−2) × 1 = 3.
Other questions people ask
What is linear interpolation?
It estimates a value between two known points by joining them with a straight line. If a table gives 4 at x = 2 and 9 at x = 3, 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₁). It is the point-slope form of a line, y − y₁ = m(x − x₁), with slope m = (y₂ − y₁) ÷ (x₂ − x₁).
How do I interpolate between two rows of a table?
Take the two rows around your value as (x₁, y₁) and (x₂, y₂). For a table with 2.339 at 20 and 3.169 at 25, the value at 22 is 2.339 + (22 − 20) × (3.169 − 2.339) ÷ 5 = 2.671.
What is the position t?
t = (x − x₁) ÷ (x₂ − x₁) says how far x is along the way from x₁ to x₂: 0 at x₁, 0.5 halfway, 1 at x₂. Then y = y₁ + t (y₂ − y₁). Graphics code calls this a lerp.
What is extrapolation?
Reading the same line outside x₁ to x₂ (t below 0 or above 1). The formula is the same, but the result is less reliable, because the data may stop following a straight line.
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. The formula would divide by x₂ − x₁ = 0.
How do I find x for a given y, or a missing point?
Use the interpolation calculator, which solves for any one of the six numbers from the other five.