# Math Help - Linear Interpolation Question

1. ## Linear Interpolation Question

Hello:
The formula: y1 * (1-x) + y2 * x is a Linear Interpolation formula. I am trying to understand if this formula will yield the middle values between two points such as: Point 1: (5,10 ) and Point 2: (20,15)

Would this be the diagonal line connecting these two points. If so, is "x" the range value from x1 to x2?. I am trying to code this in a computer function to test.

Mark

2. ## Linear interpolation

Hello mhartman

Welcome to Math Help Forum!
Originally Posted by mhartman
Hello:
The formula: y1 * (1-x) + y2 * x is a Linear Interpolation formula. I am trying to understand if this formula will yield the middle values between two points such as: Point 1: (5,10 ) and Point 2: (20,15)

Would this be the diagonal line connecting these two points. If so, is "x" the range value from x1 to x2?. I am trying to code this in a computer function to test.

Mark
I'm not sure where the formula you quote comes from, but this may help.

The midpoint of the line joining the points $(x_1,y_1)$ and $(x_2, y_2)$ is

$\Big(\frac{x_1+x_2}{2}, \frac{y_1+y_2}{2}\Big)$

So in the example you quote, it will be $\Big(\frac{5+20}{2}, \frac{10+15}{2}\Big) = (12.5, 12.5)$.

The equation of the line joining these points is:

$\frac{y-y_1}{y_2-y_1}=\frac{x-x_1}{x_2-x_1}$

which can be re-arranged as:

$y = y_1 + (x-x_1)\frac{y_2-y_1}{x_2-x_1}$

which gives you the linear interpolation formula that will calculate the value of $y$ for any value of $x$ in the interval $(x_1, x_2)$. So, for example, in the interval you quote, if you want the value of y when $x = 13$, it's

$y = 10 + (13-5)\frac{15-10}{20-5} = 10 + 8\times\frac{1}{3}= 12\tfrac23$