Gratuitous Mathematics

Monday, August 23 2004 @ 08:46 PM BST

Contributed by: robin

Here's a good one for all you maths fiends...

Map the five values 1..5 to the range 10..50. Easy, huh? (Just in case you're not clear the answer I'm looking for is 10, 20, 30, 40, 50!)

What if the range starts at zero? i.e. map 0..5 to 10..50? Hmmm, a little more tricky but do-able. Answer: 10, 18, 26, 34, 42, 50.

Now, how about mapping the values 0..40 to the range 0..1? Erm...

Actually, it's just a case of finding a generic formula to calculate the new values from the old values.

To map a series of consecutive integer values Imin .. Imax to a range of continous real values Rmin .. Rmax, I came up with the following formula:

     ( Rmax - Rmin )( Ii - Imin )
Ri = ----------------------------
           ( Imax - Imin )
where:

So, back to the original question about mapping the values 0..40 to the range 0..1.

In this example:

So, plugging these numbers into the formula gives the following values:

R1  = (1 - 0)( 0 - 0) / (40 - 0)         = 0
R2  = (1 - 0)( 1 - 0) / (40 - 0) = 1/40  = 0.025
..
R40 = (1 - 0)(39 - 0) / (40 - 0) = 39/40 = 0.975
R41 = (1 - 0)(40 - 0) / (40 - 0) = 40/40 = 1
So, now you know.

Comments (0)


robinbowes.com
http://robinbowes.com/article.php/20040823194524660