Given two points (x0,y0) and (x1,y1), estimate the value y at a query point x by linear interpolation: slope=(y1-y0)/(x1-x0), then y=y0+slope*(x-x0). Example: (1,2),(3,8) with x=2 gives slope=3 and y=5.

The slope of the line through (x0,y0) and (x1,y1) is: slope = (y1 - y0) / (x1 - x0) The interpolated value at query point x is: y = y0 + slope * (x - x0)

Example

Use a line through two data points to estimate an intermediate value.

highlighted = computed this step

Step 1 — Set up

Use points 1 comma 2 and 3 comma 8 at x equals 2.

(1,2), (3,8)x=2( 1 , 2 ),\ ( 3 , 8 )\quad x= 2

Step 2 — Slope

Compute the slope as 3.

m=3m= \hl{3}

Step 3 — Interpolate

Substitute 2 plus 3 times 1 to get 5.

2+31=52 + 3 \cdot 1 = \hl{5}

Step 4 — Result

The interpolated value at 2 is 5.

y(2)=5y( 2 )= \hl{5}
linear-interpolation Linear interpolation fits a straight line through two known points and evaluates it at any intermediate x.