Algorithm to make every number in a set positive but keep the ratios between them?

60 Views Asked by At

I don't know what tags to use for this question so if I am using the wrong ones, please suggest others.

I have a set of numbers (ex: -20, -3, 5, 8, 30). I need to make them greater than zero but preserve the ratios between them. However, if all I do is add 21 to each, the ratios change. For instance,

$5 / -20 = -0.25$

but

$26 / 1 = 26$ (added 21 to the above)

and

$8 / -20 = -0.4$

but

$29 / 1 = 29$. (added 21 to the above)

And if we divide -0.25 by -0.4 we get 0.625 while if we divide 26 by 29 we get ~0.897 so the ratios are not the same. Does anyone know how to preserve the ratios between the numbers in the set but make all the numbers positive?

1

There are 1 best solutions below

0
On

Lets say we have the set {1,2,4,-8} we can see that the ratios including -8 will always be negative and the ratios not including -8 will always be positive eg. $\frac{-8}{2}=-4$ and $\frac{2}{4}=0.5$ so we cannot make -8 positive without changing the ratios, however if we ignore the negative sign using the absolute value function denoted as |x| then we don't have negatives eg. $\frac{|-8|}{|2|}=\frac{8}{2}=4=|-4|$ we will preserve the absolute values of ratios while not including negatives.