Range scaling problem

I have a few ranges which I want to scale but I'm missing the formula (and common sense).

For example I have a scale range from 40 to 100, but I want my data to range from 0 - 100. What formula do I have to apply to my numbers? Another range I have to scale is from 8 to 35.

Thanks in advance, I really should know this stuff.

-
To rescale linearly, you are looking for the equation of a line that pairs the lower limits and pairs the upper limits, so in your first example it should go through the points $(40,0)$ and $(100,100)$, and in the second example it should go through the points $(8,0)$ and $(35,100)$. Zev's answer already gives formulas and explanations for these linear functions, but I'm mentioning this in case you have learned about linear equations from a different perspective; any method you know of finding the line connecting 2 points will work. – Jonas Meyer Jun 6 '11 at 19:16

If you have a range $[A,B]$ and want to linearly transform it to the range $[C,D]$, which is the simplest option, and I assume the one you are looking for, then the correct function is $$f(x)=C\left(1-\frac{x-A}{B-A}\right)+D\left(\frac{x-A}{B-A}\right).$$ For example, we have that $f(A)=C\cdot 1+ D\cdot0=C$, and $f(B)=C\cdot 0+D\cdot1=D$, so that the minimum of the first range gets sent to the minimum of the second range, and similarly with the maximums. Notice that as $x$ increases from $A$ to $B$, the quantity $\frac{x-A}{B-A}$ changes linearly from 0 to 1. However, there are infinitely many other, non-linear functions sending the range $[A,B]$ to the range $[C,D]$, and which one is best suited to your needs may depend on the meaning of the data you are working with.

So, to linearly scale $[40,100]$ to $[0,100]$, the function works out to $$f(x)=\frac{5}{3}(x-40),$$ and to linearly scale $[8,35]$ to $[0,100]$, the function works out to $$f(x)=\frac{100}{27}(x-8).$$

-
That works perfectly. Thanks you very much. – Kta Jun 6 '11 at 19:52
@Kta: No problem, glad to help. – Zev Chonoles Jun 6 '11 at 20:17
This simplifies a little to $C + (C-D)\dfrac{x-A}{B-A}$. – Rahul Jan 8 '13 at 15:29
Sorry, I meant $C + (D-C)\dfrac{x-A}{B-A}$. – Rahul Feb 23 '13 at 19:10

Think of it as first scaling the number down to zero (of the domain set), then multiply with the multiplying factor and then scaling it back up from zero (of the range set).

Eg: 0-100 to 0-50. Number to be scaled: 25

Make it to zero of domain          : 25-0(OF DOMAIN) = 25
Scale it                           : 25*(50-0)/(100-0) = 12.5
Make it back up from zero of range : 12.5+0(OF RANGE) = 12.5

-