Trying to solve this simple equation

63 Views Asked by At

I have something like this:

If $A > B$, then $X = A - B$, else $X = B - A$.

$X$ and $B$ are known to me, but $A$ is not known to me. Now I have $C$ (which is to basically replace $B$ in the above conditional equation). I want to get $Y$,

If $A > C$, then $Y = A - C$, else $Y = C - A$.

How can I solve for $Y$?

What I have tried so far is that I have rewritten $X^2 = (A - B)^2$ and expanded it and tried to somehow come to $(C-A)^2 = Y^2$, but I had no luck.

Can anyone help? I'm not sure if this is solvable or not. If not, then can anyone explain why?

2

There are 2 best solutions below

0
On

Assume $X \geq 0$, then

$$X = |A-B| \iff X^2 = (A-B)^2 \iff A^2 -2AB + B^2-X^2=0$$

Now solve the quadratic equation with the classical formula $A=\frac{-b \pm \sqrt{\Delta}}{2a}$ with $a=1, b = -2B, c=B^2-X^2$.

0
On

In general there can be up to two solutions since either $A=B+X$ or $A=B-X$. Also, $Y$ is essentially the distance function between $C$ and $A$ given by $Y=|C-A|$. So your two solutions are $$Y_1=|C-(B+X)|$$ $$Y_2=|C-(B-X)|$$