PDA

View Full Version : range mapping


jla2125
Jun26-09, 06:57 PM
Hey! I have a really easy question here, but I still can't figure it out.

I have a range of values from 182 to 455. I need a function that gives me back values from 1-50. IE, f(318) = 25. The numbers aren't critical, but I'd love a general equation to use for this kinda stuff. Can anybody help me out?

Thanks,
~Jeremy

mathman
Jun26-09, 07:54 PM
The simplest equation would be linear.

f(x)=1 + 49*(x-182)/(455-182)

There are obvious many other possibilities depending on the information you have.

jla2125
Jun26-09, 08:48 PM
will that form work for just about anything?

IE:
given: 1 = x1, 50 = x2, 182 = y1, 455 = y2:
f(n) = x1 + (x2 - 1)*(n - y1)/(y2 - y1)

mathman
Jun27-09, 07:03 PM
will that form work for just about anything?

IE:
given: 1 = x1, 50 = x2, 182 = y1, 455 = y2:
f(n) = x1 + (x2 - 1)*(n - y1)/(y2 - y1)

Yes: after fixing typo - should have (x2-x1)