Results 1 to 8 of 8

Thread: quadratic formulae

  1. #1

    Thread Starter
    Hyperactive Member stingrae's Avatar
    Join Date
    Apr 2002
    Location
    Sydney
    Posts
    401

    quadratic formulae

    Hi,

    I have a problem in an area in which I haven't used since high school (all those years ago).

    My boss wants me to be draw a chart with a nice compounding curve over 3 years. To do this, he has given me three values - lets say (1,30), (2,70) and (3,100).

    When I plot the graph, it appears as just three straight lines joined together. However, we want it as a parabola - i.e. compounding toward the end and looking smoother.

    My question is this: is there a way to determine the correct formula of a quadratic if you know three points of it? In other words, how does this graph look in the form of:
    y=ax2 + bx + c
    ?

    Any help would be great.

    Rodney

  2. #2
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    y-Y=a(x-X)^2
    solve x, y and a in the equation system for (X,Y)= (1,30), (2,70) and (3,100) then you have
    x=-b/(2a)
    y=c-b^2/(4a)
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  3. #3
    Hyperactive Member
    Join Date
    Mar 2002
    Location
    Boston, MA
    Posts
    391
    Hi,

    What do you mean by a nice compounding curve? And what are you using to create your plot? Depending on the tools you have available, it can be very easy to curve fit your data points. Furthermore, if you know the relationship between x and y there is no need to do any curve fitting.

    Anyway, I assume that you have MS Excel. If you don't your boss needs to get it for you if he's expecting you to make charts. Excel has the capabilities to create what it refers to as "trendlines", which (mostly) are regression curves.

    I made a chart from your data and added a 2nd-degree polynomial trendline. It fit perfectly, but keep in mind that doesn't mean that the relationship between your x and y will behave according to that polynomial over all x or even at points in between your data points. Anyway, the equation is:

    y = -5x^2 + 55x - 20

    over the range of you x values (see attachment).

    Hope this helps.

  4. #4
    Hyperactive Member
    Join Date
    Mar 2002
    Location
    Boston, MA
    Posts
    391
    Me again,

    I wanted to add some things to my last post as I think I may have misunderstood what you were trying to do. I think you were asking, and correct me if I'm wrong, what the best way to fit data to a quadratic equation.

    The method that I gave, using excel do do the job, won't help you if you're trying to program this yourself. I should also add that for three data points you're always going to get a "perfect" fit when using a quadratic. So, if you're only going to have 3 points then the method of solving a system of 3 simultaneous equations will work to determine each of the quadratic coefficients. Again, this doesn't mean that the curve represents an exact correlation to your data. You're just drawing the parabola that goes through your data. If you use more than 3 points and your data contains error, then your curve will not pass through all your data points. Therefore, you'll have to perform regression analysis to fit you quadratic equation to your data, which means you'll need to find the quadratic parameters that give the minimum error over you data range.

    General methods for polynomial regression, which quadratic regression is a subset of, are all over the internet. Try this site for example:

    www.icam.vt.edu/cliff/2074/notes/poly.pdf

    You can probably even find the code.

    Hope that helps.

  5. #5

    Thread Starter
    Hyperactive Member stingrae's Avatar
    Join Date
    Apr 2002
    Location
    Sydney
    Posts
    401
    thanks heaps for your help. I am still a little confused as to how you got that formula. I plugged in the test values and it was spot on.

    Are you able to write the solution for how you got
    y=-5x^2 + 55x - 20 ?

    I need to be able to plot this for several different values. You mentioned to see the attachment but I wasn't able to find it.

    To chart this, I am using the budget MSChart control shipped with VB6. I plugged your formula into a function and it plotted well. Not too pretty but it does the job quickly and easily.

    Thanks in anticipation.

  6. #6
    Hyperactive Member
    Join Date
    Mar 2002
    Location
    Boston, MA
    Posts
    391
    Hi,

    I used Excel to do the curve fitting, which doesn't help you much since you need to develop code for it.

    I'm sorry I don't have any source code for doing that. I'm certain that there are methods available for free if you look. You could probably pick up a book on data regression at the library.

    Sorry that I couldn't be of more help. You might want to consider attempting to linearize the quadratic and then use linear regression, which is pretty easy.

    Can anyone else here offer more help?

  7. #7
    Frenzied Member
    Join Date
    Jul 1999
    Location
    Huntingdon Valley, PA 19006
    Posts
    1,151
    y = ax^2 + bx +c is the general equation of a second degree curve.

    If you have three points, just put the values into the above and you will have 3 equations in three unknowns.

    For example, one ouf your points was (1, 30). Using that point, you get

    30 = a + b + c


    Another point was (2, 70), which leads to.

    70 = 4a + 2b + c
    Live long & prosper.

    The Dinosaur from prehistoric era prior to computers.

    Eschew obfuscation!
    If a billion people believe a foolish idea, it is still a foolish idea!
    VB.net 2010 Express
    64Bit & 32Bit Windows 7 & Windows XP. I run 4 operating systems on a single PC.

  8. #8
    Hyperactive Member
    Join Date
    Mar 2002
    Location
    Boston, MA
    Posts
    391
    Perhaps I misunderstood the original post.

    If you have points that lie EXACTLY on the parabola, then you won't need any regression and you can solve the problem just as Guv outlined below by solving a system of 3 linear equations. Keep in mind that if you have only three points (the minimum you need) then they will always fit a parabola perfectly.


    Stingrae, is that your problem? If so, then it's pretty straightforward and you can just ignore everything that I wrote. Where are these numbers coming from? I would be surprised to learn that you are getting these numbers from somewhere without knowing the function that generates them if they in fact lie exactly on a parabola. However, if the points you are plotting will not always lie EXACTLY on a parabola then you will have to do regression analysis to determine the quadratic coeficients that give you the best fit.
    Last edited by wy125; Apr 3rd, 2002 at 04:44 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width