A friend asked me today about how to normalize a range into another one. Well, given a range from A to B we want to convert it to a scale of C to D, where A maps to C and b maps to D, and we want to do it with a linear function. For example, if C=1 and D=5, ie, interval [1,5], that means that A maps 1 and B maps 5.
The following linear equation does exactly what we need
f(x) = 1 + (x-A)*(5-1)/(B-A)
because
f(A)=1 + (A-A)*(5-1)/(B-A) = 1+0 = 1and
f(B)=1 + (B-A)/(B-A)*(5-1) = 1 + 1*(5-1) = 5.
In general, the linear ecuation looks like:
f(x) = C + (x-A)*(D-C)/(B-A)Easy peasy, isn't it?
Hope help!
No comments:
Post a Comment