What is the code for a program that will calculate the qudratic eqatuion! Your help will be greatly appreciated.
Printable View
What is the code for a program that will calculate the qudratic eqatuion! Your help will be greatly appreciated.
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.
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
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:
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 Dim dblDescriminant As Double QuadraticFormula = False dblDescriminant = (b * b) - (4 * a * c) If dblDescriminant < 0 Then Exit Function dblPosRoot = (-b + Sqr(dblDescriminant)) / (2 * a) dblNegRoot = (-b - Sqr(dblDescriminant)) / (2 * a) QuadraticFormula = True End Function 'to use it to solve ax² + bx + c = 0 Dim dblPosRoot As Double 'holds the "positive" root Dim dblNegRoot As Double 'holds the "negative" root If QuadraticFormula(a, b, c, dblPosRoot, dblNegRoot) Then Debug.Print "the roots are"; dblPosRoot; "and"; dblNegRoot Else Debug.Print "the roots are imaginary" End If