Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Java (http://www.chiefdelphi.com/forums/forumdisplay.php?f=184)
-   -   Complex math equation (http://www.chiefdelphi.com/forums/showthread.php?t=103823)

neal 25-02-2012 17:38

Complex math equation
 
I was wondering if someone could help me figure out an equation for:

I want to scale a double (between 8-13) to be from 0 - 100.
So 8 will be 0, 9 will be 20, 13 will be 100, 12.5 will be 90 and so on.

I hope that makes sense and would appreciate if someone could help.

Thanks in advance!

Ether 25-02-2012 17:42

Re: Complex math equation
 
Quote:

Originally Posted by neal (Post 1134756)
I was wondering if someone could help me figure out an equation for:

I want to scale a double (between 8-13) to be from 0 - 100.
So 8 will be 0, 9 will be 20, 13 will be 100, 12.5 will be 90 and so on.

I hope that makes sense and would appreciate if someone could help.

Thanks in advance!


y = 20*x - 160



connor.worley 25-02-2012 17:42

Re: Complex math equation
 
Well, you have a range of 5 and you want to scale that to a range of 100, so you'll need to multiply by 20. You want to start at 8 though, so you need to subtract 8 * 20.

output = 20*input - 160

neal 25-02-2012 17:46

Re: Complex math equation
 
Thanks Ether and Connor!

Cal578 25-02-2012 19:33

Re: Complex math equation
 
You should know the general process for figuring this out, just in case your situation changes and you want a new formula.

You want:
y = m * x + b

and you want this to be true for x=8 -> y=0, and for x=13 -> y=100.

So, you have two equations to solve for two variables:
0 = m * 8 + b
100 = m * 13 + b

If you subtract the first equation from the second, the b terms will cancel out:
100 = m * (13 - 8)
100 = m * 5
20 = m

Substitute 20 into either of the equations (the first is easier):
0 = 20 * 8 + b
b = -160

I hope this is helpful. When I saw the thread title "Complex math equation", I thought we were going to discuss real and imaginary numbers. A math geek gets easily excited...

Ether 25-02-2012 20:04

Re: Complex math equation
 


Just use the two-point formula:

y = y1+(x-x1)/(x2-x1)*(y2-y1)

with x1=8, x2=13, y1=0, y2=100 this gives y = 20*(x-8)

or plot your data in Excel

8,0
9,20
12.5,90
13,100

to see the shape, and then

click on "add trendline" and select an appropriate model (linear in this case) to fit (and it will give you the equation)



All times are GMT -5. The time now is 09:53.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi