|
-
Mar 16th, 2010, 08:45 PM
#1
Thread Starter
New Member
Quadratic Equation
Here is the thing:
I am trying to write a quadratic equation solver in Excel 2003 using Vba, creating my own formula, but I cannot figure out how to get it to display the complex roots. This is the formula, just for the first root. It is going to be the same for the second one, just changing the signs where I have to:
Function quad1(a, b, c)
If IsNumeric(a) And IsNumeric(b) And IsNumeric(c) Then
If ((b ^ 2) - (4 * a * c)) >= 0 Then
quad1 = Format((((-b) + (Sqr((b ^ 2) - (4 * a * c)))) / (2 * a)), "0.00")
Else:
quad1 = ((-b) / (2 * a)) & (i * ((Sqr(-((b ^ 2) - (4 * a * c)))) / (2 * a)))
End If
Else
quad1 = "Input a numeric value"
End If
End Function
The part that I have to fix is:
quad1 = ((-b) / (2 * a)) & (i * ((Sqr(-((b ^ 2) - (4 * a * c)))) / (2 * a)))
Any suggestions are welcome. Thanks !
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
|