Create Absolute Value Equation from 2 lines I am trying to convert these 2 lines for an absolute value equation:
$$y=\frac{10}{10-a}(x-a)$$
$$y=\frac{10}{a}(x-a)$$
$a$ is a parameter that has bounds $(0, 10)$.
The absolute value equation should use the first equation for positive y values and second equation for negative y values
Here's a desmos link so you can easily see it: https://www.desmos.com/calculator/itxtp5eyij
The reason for this is I am trying to calculate priority for tasks. $a$ is the amount of the task already completed on a range of 0 to 10, and $x$ is the time elapsed. ($x=10$ means all the time has elapsed)
The $y$ value would be the priority of the task. For example, if $a=10$ and $x=0$ it means that the task has been completed as soon as it started. Priority would start at -10 and increase over time until it hits zero.
Similarly, if $a$ remains 0, as $x$ approaches 10, the priority would also increase to 10 at the same rate
Any help converting this to an absolute value would be appreciated, although the main goal is to just have a concise code implementation for this (it's for an app)
 A: https://www.desmos.com/calculator/8xizt66y8k
Here's my solution.
The idea is to use an absolute value expression as a coefficient for each line you want, and have that expression equal zero when you dont want that line's value.
$\frac{\left(\left|x-a\right|+x-a\right)}{2\left(x-a\right)}$ will be equal to 1 when $x>a$, and 0 when $x<a$
$\frac{\left(\left|a-x\right|+a-x\right)}{2\left(a-x\right)}$ will be equal to 1 when $x<a$, and 0 when $x>a$
so
$\frac{\left(\left|x-a\right|+x-a\right)}{2\left(x-a\right)}\frac{10}{10-a}(x-a)+\frac{\left(\left|a-x\right|+a-x\right)}{2\left(a-x\right)}\frac{-10}{0-a}(x-a)$ will be equal to $\frac{10}{10-a}(x-a)$ when $x>a$, and will be equal to $\frac{-10}{0-a}(x-a)$ when $x<a$
hope that helps!
Note: This is undefined for $x=a$,but in that case $y=0$ anyway. Also it is undefined for $a=0$ and $a=10$, but it was that way for your original piecewise function anyway.
edit: there might be a better solution to this, but this is what I could come up with off the top of my head.I'd love to see something prettier though.
