Linear interpolation

See: wikipedia on linear interpolation.

Let us say that we have two known points x1,y1 and x2,y2.

Now we want to estimate what y value we would get for some x value that is between x1 and x2. Call this y value estimate — an interpolated value.

Two simple methods for choosing y come to mind. The first is see whether x is closer to x1 or to x2. If x is closer to x1 then we use y1 as the estimate, otherwise we use y2. This is called nearest neighbor interpolation.

The second is to draw a straight line between x1,y1 and x2,y2. We look to see the y value on the line for our chosen x. This is linear interpolation.

It is possible to show that the formula of the line between x1,y1 and x2,y2 is:

y=y1+(xx1)y2y1x2x1

(png, hires.png, pdf)

_images/linear_interpolation-1.png