Transforming distances between $2$ numbers into a $0-100$ scale

27 Views Asked by At

I need a formula that will scale the distance of a variable from another variable between $0$-$100$

For example:

$1$st variable $400$ $2$nd variable $900$ Distance $= 500$ Answer $= X$

$1$st variable $-400$ $2$nd variable $100$ Distance $= 500$ Answer $= X$

The formula should return the same value for $X$ in both scenarios because both of the $1$st variables have an absolute value of $400$ and both $2$nd variables are at a distance of $500$

A distance of $0$ should $= 100$ An answer of $0$ should be impossible, as distance goes up the answer should get closer to $0$ but never reach absolute $0$ and the rate at which it gets closer to $0$ should be based on the absolute value of the $1$st variable

1

There are 1 best solutions below

0
On

Let $v_1$ be the first variable and $v_2$ be the second variable, le

$$f(v_1, v_2)=100\exp(-(|v_1|+\epsilon)|v_1-v_2|)$$

where $\epsilon$ is a positive number.

If the $v_1=v_2$, then $f(v_1,v_2)=100$.

as $|v_1-v_2|$ increases, $f(v_1,v_2)$ decreases but never hit zero.