I'm kind of stuck here, I guess it's a bit of a brain teaser. If I have numbers in the range between 0.5 to 1 how can I normalize it to be between 0 to 1?
Thanks for any help, maybe I'm just a bit slow since I've been working for the past 24 hours straight O_O
Others have provided you the formula, but not the work. Here's how you approach a problem like this. You might find this far more valuable than just knowning the answer.
To map [0.5, 1]
to [0, 1]
we will seek a linear map of the form x -> ax + b
. We will require that endpoints are mapped to endpoints and that order is preserved.
Method one: The requirement that endpoints are mapped to endpoints and that order is preserved implies that 0.5
is mapped to 0
and 1
is mapped to 1
a * (0.5) + b = 0 (1)
a * 1 + b = 1 (2)
This is a simultaneous system of linear equations and can be solved by multiplying equation (1)
by -2
and adding equation (1)
to equation (2)
. Upon doing this we obtain b = -1
and substituting this back into equation (2)
we obtain that a = 2
. Thus the map x -> 2x - 1
will do the trick.
Method two: The slope of a line passing through two points (x1, y1)
and (x2, y2)
is
(y2 - y1) / (x2 - x1).
Here we will use the points (0.5, 0)
and (1, 1)
to meet the requirement that endpoints are mapped to endpoints and that the map is order-preserving. Therefore the slope is
m = (1 - 0) / (1 - 0.5) = 1 / 0.5 = 2.
We have that (1, 1)
is a point on the line and therefore by the point-slope form of an equation of a line we have that
y - 1 = 2 * (x - 1) = 2x - 2
so that
y = 2x - 1.
Once again we see that x -> 2x - 1
is a map that will do the trick.