|
-
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 !
-
Mar 16th, 2010, 09:47 PM
#2
Re: Quadratic Equation
Don't look at this link if you want to do this all by yourself. Many times when I need to a little help with an equation (espcially Trig as I hate it so), I do a quick forum search here or on google. The link was the first VB-related hit.
P.S. Welcome to the forums!
Last edited by LaVolpe; Mar 16th, 2010 at 10:04 PM.
-
Mar 17th, 2010, 05:12 AM
#3
Re: Quadratic Equation
Thread moved from 'VB6' forum to 'Office Development/VBA' forum.
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
|