[Math] Equation for line between three points

graphing-functionslinear algebra

I have three points: $(0,0),(2,1),(3,2)$ and I get a graph like this:

Graph of points (0,0)(2,1)(3,2)

Is there a formula to draw this graph with the line (or two lines meeting in the middle, if you prefer- but definitely not a curve) continuing straight/linearly in both directions indefinitely?

I've hacked together an excel formula that uses a "IF" but it seems inelegant.

Best Answer

The simplest way to represent your function is indeed with an if:

For $x \leq 2$, you have $f(x)=\frac{x}{2}$, and for $x \geq 2$, you have $f(x)=x-1$. I assume here that the unit of a square in your graph is 0.5 and that the 3 dots represent the 3 points you are talking about (difference with @Chickenmancer)

Then $$f(x)=\left\{\begin{array}{cc} \dfrac{x}{2}, &\text{for } x\leq 2,\\ x-1, &\text{for } x>2.\end{array}\right. $$

If you don't want this if (or this disjunction of case), you can see that your function is actually the maximum of these 2 affine functions.

Therefore $f(x)=\max(\frac{x}{2}, x-1)$.

And we can "simplify" this expression using the fact that $\max(a,b)=\frac{|a-b|}{2}+\frac{a+b}{2}$:

$$\boxed{f(x)=\dfrac{|x-2|}{4}+\dfrac{3x-2}{4}}$$

Related Question