# What is the linear interpolation?

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.

- Page: https://www.acalculator.org/math/interpolation-calculator
- JSON spec: https://www.acalculator.org/math/interpolation-calculator.json
- Version: 287d45da8d66

## Default answer

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).

## Inputs

| Key | Label | Description |
| --- | --- | --- |
| x1 | x₁ | The x value of the first known point. |
| y1 | y₁ | The y value of the first known point. |
| x2 | x₂ | The x value of the second known point. It must differ from x₁. |
| y2 | y₂ | The y value of the second known point. |
| x | x | The x value to read the line at. |
| y | y | The y value on the line at x: the interpolated value. |

## Outputs

| Key | Label | Description |
| --- | --- | --- |
| x1 | x₁ | The x value of the first known point. |
| y1 | y₁ | The y value of the first known point. |
| x2 | x₂ | The x value of the second known point. It must differ from x₁. |
| y2 | y₂ | The y value of the second known point. |
| x | x | The x value to read the line at. |
| y | y | The y value on the line at x: the interpolated value. |

## Method

y = y₁ + (x − x₁)(y₂ − y₁) ÷ (x₂ − x₁): the straight line through (x₁, y₁) and (x₂, y₂), read at x.

## Assumptions

- 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

1. x1 = 2, y1 = 4, x2 = 3, y2 = 9, x = 2.5 gives y = 6.5. Source: hand calculation in content.mdx: 4 + (2.5 − 2)(9 − 4) ÷ (3 − 2) = 6.5.
2. x1 = 2, y1 = 4, x2 = 3, y2 = 9, x = 4 gives y = 14. Source: hand calculation in content.mdx: 4 + (4 − 2) × 5 ÷ 1 = 14 (extrapolation beyond x₂).
3. x1 = 2, y1 = 4, x2 = 3, y2 = 9, y = 6 gives x = 2.4. Source: hand calculation in content.mdx: x = 2 + (6 − 4)(3 − 2) ÷ (9 − 4) = 2.4.
4. x1 = -1, y1 = 5, x2 = 4, y2 = -5, x = 0 gives y = 3. Source: hand calculation in content.mdx: 5 + (0 + 1)(−5 − 5) ÷ (4 + 1) = 5 − 2 = 3.
5. x1 = 0, y1 = 0, x2 = 10, x = 4, y = 2 gives y2 = 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.

## FAQ

### 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.

## Sources

- NIST Digital Library of Mathematical Functions, §3.3(i) Lagrange Interpolation, equation 3.3.1 (the two-point case, n = 1, is the straight line through the two points). https://dlmf.nist.gov/3.3
- OpenStax, College Algebra 2e, §2.2 Linear Equations in One Variable (slope m = (y₂ − y₁) ÷ (x₂ − x₁) and the point-slope form y − y₁ = m(x − x₁)). https://openstax.org/books/college-algebra-2e/pages/2-2-linear-equations-in-one-variable
