Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Math equation for scaling number between two limits not starting at 0? [closed]

Tags:

math

For example, I have a number between 1~100 and I need to scale it to be between 20~80.

Examples:

1 scales to 20
100 scales to 80
50 scales to 50
like image 257
Bill Software Engineer Avatar asked Oct 11 '11 19:10

Bill Software Engineer


2 Answers

You're looking for a function f such that :

f(x) = ax +b

f(1)=20
f(100)=80

Then

a+b=20
100a+b=80

You get :

99a +20 = 80

then a =60/99=20/33
and b = 20 - 20/33 = 20*(32/33)

Have a look at this question for more information :

Invert and convert slider value

Note: if 50 scales to 40 your transformation is not linear. So you need to look for another type of function:

f(x) = ax**2 + b x + c

like image 176
Ricky Bobby Avatar answered Sep 23 '22 20:09

Ricky Bobby


You need to be more specific about what you're looking for. The rules you given do not produce a consistent LINEAR scaling.

For, if it were linear:

(1, 20) is on the line
(100, 80) is one the line

Slope is:

(80 - 20) / (100 - 1) = 60 / 99

Line is

y - 20 = (60 / 99) * (x - 1)

Then:

y = (60 / 99) * (x - 1) + 20

Then, testing x = 50:

y = (60 / 99) * (50 - 1) + 20 = 2940 / 99 + 20 != 40

Thus, there is no such LINEAR scaling.

like image 44
jason Avatar answered Sep 26 '22 20:09

jason