|
-
Sep 13th, 2001, 02:34 PM
#1
Thread Starter
New Member
Quadratic Equation
What is the code for a program that will calculate the qudratic eqatuion! Your help will be greatly appreciated.
-
Sep 13th, 2001, 03:52 PM
#2
Lively Member
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.
-
Sep 13th, 2001, 07:21 PM
#3
Thread Starter
New Member
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
-
Sep 13th, 2001, 08:08 PM
#4
Fanatic Member
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
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|