Take the 2-minute tour ×
Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. It's 100% free, no registration required.

This question already has an answer here:

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?

share|improve this question

marked as duplicate by Rahul, Stefan Hansen, AWertheim, O.L., Dennis Gulko Jun 7 '13 at 7:21

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

2 Answers 2

up vote 2 down vote accepted

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$.

share|improve this answer
    
So in my case, assuming a to be -5 and b to be 5, then wouldn't x's range be 0 to b - a, which would equal 10? –  Peter Kazazes Jun 17 '12 at 1:56
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! –  Gerry Myerson Jun 17 '12 at 2:00

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

share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.