A formula for rescaling a range of positive values onto a range which includes negative ones

31 Views Asked by At

I have a random number generated in a computer programme which produce values from 1 to 100. I want to map this range in order to comply with the following rules $$ \begin{align} \text{number }&100\text{ should be mapped to }100\\ \text{number }&50\text{ should be mapped to } 0\\ \text{number }&0\text{ should be mapped to }-100\\ \end{align} $$

I am interested to know how to do this transformation (is that even the right word?) It is a long time since I did any mathematics. More formally, calling $t$ the sought for mapping,

$$ \begin{align} t(100) &= 100\\ t(50) &= 0\\ t(0) &= -100 \end{align} $$

2

There are 2 best solutions below

2
On BEST ANSWER

It looks like you want a function: some operations that take a value in, and after those operations are applied, return another value.

All these points pass through a line since the slope is the same. For example, using the points $(0,-100)$ and $(50,0)$, the slope is $\frac{y_2-y_1}{x_2-x_1} = \frac{0-(-100)}{50-0} = 2$. You can verify that $(50,0)$ and $(100,0)$ return the same slope.

The standard form of a line is $y=mx+c$. $y$ is the $y$-value which is the same as the output value, $m$ is the slope, and $c$ is the $y$-intercept (where the line intersects the $y$-axis).

We have already found the slope is $2$. Now substituting any pair of $(x,y)$ into $y=mx+c$, we have $(0)=2(50)+c$, so $c=-100$.

Therefore the function you need is $y = 2x-100$.

0
On

If your number $N$ is between $0$ and $100$, your can get the new number $N'$ using $2N-100$. In general, you can write a linear transformation $x'=ax+b$. By plugging in the initial maxima and minima, and the desired maxima and minima, you can get the $a$ and $b$ constants: $$x'_{max}=ax_{max}+b\\x'_{min}=ax_{min}+b$$ By subtracting the second equation from the first, you get $$a=\frac{x'_{max}-x'_{min}}{x_{max}-x_{min}}$$ Then get $b$ from any of the original equations. To check, $x_{max}=100$, $x_{min}=0$, $x'_{max}=100$, $x'_{min}=-100$ yield $$a=\frac{100-(-100)}{100-0}=2$$ Then $$100=2\cdot 100+b$$ or $b=-100$