Results 1 to 4 of 4

Math Help - For a piece of code

  1. #1
    Newbie
    Joined
    Feb 2011
    Posts
    2

    For a piece of code

    Hey there everyone. I hope i got the right forum here. I really, quite desperately need this graph -

    turned into an equation i can use in my lua programming script. If anyone could do this for me, i'd be eternally greatful.. thank you.
    Follow Math Help Forum on Facebook and Google+

  2. #2
    Grand Panjandrum
    Joined
    Nov 2005
    From
    someplace
    Posts
    14,972
    Thanks
    4
    Quote Originally Posted by RogueFighter View Post
    Hey there everyone. I hope i got the right forum here. I really, quite desperately need this graph -

    turned into an equation i can use in my lua programming script. If anyone could do this for me, i'd be eternally greatful.. thank you.
    It would help if you gave some background on what this curve represents.

    CB
    Follow Math Help Forum on Facebook and Google+

  3. #3
    Newbie
    Joined
    Feb 2011
    Posts
    2
    Quote Originally Posted by CaptainBlack View Post
    It would help if you gave some background on what this curve represents.

    CB
    It doesnt represent anything really, its just out of my mind. Its a weight to speed ratio graph. The less lines that are in my piece of code, the more efficiently it will run. I just really need something thats one line and tells the code to replicate that, that isnt

    if(weight) =>50
    then(speed) ( 1 )
    elseif(weight) ==49
    then(speed) ( 2 )

    Something with so many lines of code will run sluggishly.
    Follow Math Help Forum on Facebook and Google+

  4. #4
    MHF Contributor

    Joined
    Apr 2005
    Posts
    15,725
    Thanks
    1478
    First, there are an infinite number of functions that would give graphs that look like what you have given. However, you can look for the easiest. It clearly is not a straight line so lets try quadratic. Any quadratic will be of the form y= ax^2+ bx+ c so we need three data points to determine those three coefficients. Just looking at your graph it looks like weight is 50 when speed is 0, weight 25 when speed is 25, and weight is 0 when speed is 35.

    But apparently you want speed as a function of weight (your graph has "dependent" and "independent" axes swapped from the usual convention) so you want (50, 0), (25, 25), and (0, 35).

    Putting those values into the equation,
    a(0)^2+ b(0)+ c= c= 35
    a(25)^2+ b(25)+ c= 625a+ 25b+ 35= 25
    and
    a(50)^2+ b(50)+ c= 2500a+ 50b+ 35= 0

    Multiplying the second equation by 2 gives 1250a+ 50b= -20 while the third equation is 2500a+ 50b= -35. Subtracting eliminates b: 1250a= -15 so that a= -\frac{3}{250}.

    Putting that back into 1250a+ 50b= -20 (or just 125a+ 5b= -2) we have -\frac{3}{2}+ 5b= -2 so 5b= -\frac{4}{2}+ \frac{3}{2}= -\frac{1}{2} and b= -\frac{1}{10}.

    So one possible function is y= -\frac{3}{250}x^2- \frac{1}{10}x+ 35. That will exactly fit the points I chose:
    -\frac{3}{250}(0)^2- \frac{1}{10}(0)+ 35= 35
    -\frac{3}{250}(25)^2- \frac{1}{10}(25)+ 35= 25
    -\frac{3}{250}(50)^2- \frac{1}{10}(50)+ 35= 0
    but probably will not go exactly through other points.

    For example, from your graph it appears that a weight of 15 corresponds to a speed of 30. Setting x= 15, -\frac{3}{250}(15)^2- \frac{1}{10}(15)+ 35= 30.8 instead- close but not exact. If you wanted that point to be exact also, you could go up to third power giving you another coefficient and another point to use. But then there would be other points at which the function would not be exact.
    I suspect that y= -\frac{3}{250}x^2- \frac{1}{10}x+ 35, where "x" is the weight and "y" is the speed, is the best simple function you will find to fit this graph.
    Follow Math Help Forum on Facebook and Google+

Similar Math Help Forum Discussions

  1. Piece Wise - Limits
    Posted in the Calculus Forum
    Replies: 2
    Last Post: April 7th 2010, 06:17 PM
  2. Derivative piece function
    Posted in the Calculus Forum
    Replies: 0
    Last Post: November 1st 2009, 01:45 PM
  3. A Piece of Wire
    Posted in the Calculus Forum
    Replies: 12
    Last Post: December 31st 2008, 09:22 AM
  4. Piece-wise functions, please help
    Posted in the Pre-Calculus Forum
    Replies: 1
    Last Post: September 9th 2008, 05:26 PM
  5. Portfolio Piece Question
    Posted in the Algebra Forum
    Replies: 3
    Last Post: February 29th 2008, 07:28 AM

Search Tags


/mathhelpforum @mathhelpforum