3
$\begingroup$

I have a large array of variable-integer keypairs. The integer values range from -5 to 5. I'd like to scale that data to a range of 0 to 2. Logically, -5 would become 0, 0 would become 1 and 5 would become 2. How should I go about doing this on a large scale and with different input ranges?

2 Answers 2

4

If $x$ ranges from $a$ to $b$, then $x-a$ ranges from $0$ to $b-a$, so $(x-a)/(b-a)$ ranges from $0$ to $1$, so $(d-c)(x-a)/(b-a)$ ranges from $0$ to $d-c$, so ${(d-c)(x-a)\over b-a}+c$ ranges from $c$ to $d$.

  • 1
    Work through what I wrote: $x$ ranges from -5 to 5, $x+5$ ranges from 0 to 10, $(x+5)/(5-(-5))$ ranges from 0 to 1, $(2-0)(x+5)/10$ ranges from 0 to 2, voila!2012-06-17
0

Scale linearly. It is easy to find slope, y-intercept and a little formula.