Results 1 to 4 of 4

Thread: Quadratic Equation

  1. #1

    Thread Starter
    New Member
    Join Date
    Sep 2001
    Posts
    8

    Question Quadratic Equation

    What is the code for a program that will calculate the qudratic eqatuion! Your help will be greatly appreciated.

  2. #2
    Lively Member
    Join Date
    Jun 2001
    Location
    Banana Republic
    Posts
    115
    I guess, you want the equation from known roots..

    If a,b be the two roots

    and S be their sum, P be their products...

    X2-(S)X+P = 0

    is the equation.

  3. #3

    Thread Starter
    New Member
    Join Date
    Sep 2001
    Posts
    8

    No...

    No, I am trying to make a program in visual basic that will calculate the quadratic equation and i can't get it to work. I was needing some help if anyone is able. Thanks again...

    Corey

  4. #4
    Fanatic Member Kaverin's Avatar
    Join Date
    Oct 2000
    Posts
    930
    Do you mean solve a quadratic equation? If not, explain what you mean more clearly. If you're trying to solve one, you could use this if you wanted.
    VB Code:
    1. Public Function QuadraticFormula(ByVal a As Double, ByVal b As Double, ByVal c As Double, ByRef dblPosRoot As Double, ByRef dblNegRoot As Double) As Boolean
    2.    Dim dblDescriminant As Double
    3.    QuadraticFormula = False
    4.    dblDescriminant = (b * b) - (4 * a * c)
    5.    If dblDescriminant < 0 Then Exit Function
    6.    dblPosRoot = (-b + Sqr(dblDescriminant)) / (2 * a)
    7.    dblNegRoot = (-b - Sqr(dblDescriminant)) / (2 * a)
    8.    QuadraticFormula = True
    9. End Function
    10.  
    11. 'to use it to solve ax² + bx + c = 0
    12. Dim dblPosRoot As Double 'holds the "positive" root
    13. Dim dblNegRoot As Double 'holds the "negative" root
    14. If QuadraticFormula(a, b, c, dblPosRoot, dblNegRoot) Then
    15.    Debug.Print "the roots are"; dblPosRoot; "and"; dblNegRoot
    16. Else
    17.    Debug.Print "the roots are imaginary"
    18. End If
    I'm baaaack...
    VB5 Professional Edition, VC++ 6
    Using a 1 gHz Thunderbird, 256 mb RAM, 40 gb HD system with Win98se

    I feel special because I finally figured out how to loop midis: Post link
    I'm a fanatic too

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