Mathematical equation for scaling a number between two limits, not starting at 0?

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

Examples:

1 scales to 20
100 scales to 80
50 scales to 50
+5
source share
2 answers

You are 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 are up to 40, your conversion is not linear. Therefore, you need to look for another type of function:

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

+9
source

You need to be more specific about what you are looking for. The rules you quoted do not provide consistent LINEAR scaling.

, :

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

:

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

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

:

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

x = 50:

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

, .

+1

All Articles