[RESOLVED] Easy math question
I suck at math.
There is a ranking system that stores a rating from 1 to 3 (1 being bad, 3 being best).
So there is a list of thousands of ratings all from 1 to 3.
To get an average...add up all the ratings and divide by how many there are (simple enough).
But to display that as a score of 1 to 10, (instead of 1 to 3) how would you do that? :confused:
Re: [RESOLVED] Easy math question
In this case, the formula comes about like this:
You have numbers from 1-3, you want to map them to numbers from 1-10. (1) First shift the numbers from 1-3 to the range 0-2. (2) Now multiply that range from 0-2 by 4.5 to get a range from 0-9. (3) Now shift the range from 0-9 to 1-10.
Algebraically this becomes
(1) A = (AvgRating - 1); A is in the range 1-3 minus 1 = 0-2
(2) B = A*4.5; B is in the range 0-2 times 4.5 = 0-9;
(3) C = B + 1 = Your Answer; C is in the range 0-9 plus 1 = 1-10.
Combine 1, 2, and 3 by substitution to get
C = B + 1 = A*4.5 + 1 = (AvgRating - 1)*4.5 + 1 = AvgRating*4.5 - 4.5 + 1 = AvgRating*4.5 - 3.5 = your answer.
Alternatively, you can think of it as getting the 1 AvgValue to map to 1, and getting the 3 AvgValue to map to 10, using a "linear" map. That is,
f(1) = 1,
f(3) = 10,
f(AvgRating) is linear.
You might remember linear functions from an algebra course. In this context, we know that f must be of a certain form:
f = a*AvgRating+b
where a and b are some constants. If you graph f, you'll see that it ascends or descends smoothly, like your 1-10 rating scale should, which is why we use a linear function here instead of something crazy.
With the above, finding a and b is all algebra:
f(1) = a*1+b = a + b = 1 -> a = 1-b
f(3) = a*3+b = 3a + b = 3(1-b)+b = 3-2b = 10 -> 2b = -7 -> b = -7/2 = -3.5 -> a = 1-(-3.5) = 4.5, so we have
f(AvgRating) = 4.5*AvgRating - 3.5 = your answer.
Anhn and Logophobic used generalizations of this technique which allow the easy scaling from one coordinate system (one linear range) to another. For instance, you can create the Celsius to Fahrenheit conversion formula from this:
Quote:
Originally Posted by Logophobic
Value2 = (Value1 - R1.Low) * (R2.High - R2.Low) / (R1.High - R1.Low) + R2.Low
We're converting from system R1 where we have a low and high end to the scale, as well as a value, to the system R2. Let's convert from Fahrenheit to Celsius, so using limits we know the conversions for,
Freezing Points: R1.Low = 32 deg F, R2.Low = 0 deg C
Boiling Points: R1.High = 212 deg F, R2.High = 100 deg C.
Value1 will then of course be in [answer this yourself first if you wish to truly follow along] the scale that begins with the letter F, and Value2 will be in Celsius. Let's make this more obvious by using these names:
Value1 = F,
Value2 = C.
Then the conversion formula falls out to be
C = (F-32)*(100-0)/(212-32) = (F-32)*100/180 = (F-32)*5/9, which might be a familiar formula to you.
You can check this formula, among other ways, by checking what F = -40 gives. Perhaps you'll recall that F and C scales are actually equivalent at -40 degrees, so C should be -40 here:
C = (-40-32)*5/9 = (-72)*5/9 = (-8*9)*5/9 = -8*5 = -40.
Yay, it works. This same method was used in your case to provide your magical formula, and can be proven using the second explanation from above, or even (if you're a bit more creative) the first explanation.
I hope this helped make the math seem a bit less mystical :)
1 Attachment(s)
Re: [RESOLVED] Easy math question
The graph below may help to understand a little bit more.
Code:
With equation : y = a*x + b
a is the slop of the line:
y2 - y1 10 - 1
a = ––––––– = –––––– = 4.5
x2 - x1 3 - 1
b = -3.5 is the value of y when x = 0
Re: [RESOLVED] Easy math question
Thanks jemidiah and ahn.
I remember learning slopes in basic algebra class (which I hate to admit, but I did not do too well in).
Thanks for explaining it me. :)