Changing the Scale of a List of Numbers

I have a set of numbers, {2,3,2,4,5,10,9,9,7,12}, and I would like to change the scale. Want the lowest value to be a 1 and the highest value a 5, and the rest should map accordingly. Assuming I want to do this linearly, it’s as simple as two mx+b=c and solving for m and b.

Here’s the simple solution:

sH is the high bounds of the new scale.
sL is the low bounds of the new scale.
vmax is the max value in your original set.
vmin is the min value in your original set.
Using these values, calculate m and b:

m = (sH – sL) / (vmax – vmin)\r\n* b = sH – vmax*m
Now using the m and b values, find the scaled values for each item in your set:

m*orignalvalue + b = scaledvalue
Using my example set of {2,3,4,5,7,9,10,12} and scaling between 1 and 5.

m = (5-1)/(12-2) = 4 / 10 = 0.4
b = 5 – 12.4 = 5 – 4.8 = 0.2
x + 0.2 = y
Applying this to the original set, we end up with {1, 1.4, 1.8, 2.2, 3, 3.8, 4.2, 5}.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.