Databases Reference
In-Depth Information
If discriminant < 0 Then
discriminant = Abs(discriminant)
complex = True
End If
Select Case RootNumber
Case 1
Select Case complex
Case True
real = -b / (2 * a): cmplx = Sqr(discriminant) / (2 * a)
AdvQuadEq = real & " + " & cmplx & "i"
Case False
AdvQuadEq = (-b + Sqr((discriminant))) / (2 * a)
End Select
Case 2
Select Case complex
Case True
real = -b / (2 * a): cmplx = Sqr(discriminant) / (2 * a)
AdvQuadEq = real & " - " & cmplx & "i"
Case False
AdvQuadEq = (-b - Sqr((discriminant))) / (2 * a)
End Select
End Select
End Function
If the following function is used to calculate the roots of Equation 4.4, the following will be
returned:
Root 1: 0
+
2i
Root 2: 0
2i
The resulting roots from this factorization contain only an imaginary component. Notice that i is
appended to the end of the complex number to signify that it is the imaginary portion of the complex
number. (Some mathematical references utilize j as opposed to i .) Recall that i is
i
=−
1
(4.6)
15), the subroutine
returns the following results, which contain both a real and imaginary component:
If Equation 4.3 is modified to have complex roots by changing the (15) to (
+
Root 1: 1
+
3.741657i
Root 2: 1
3.741657i
For functions with real roots, a single number is returned as in the earlier example. Now that a
function has been developed to calculate the roots of quadratic equations using the quadratic
formula, the question is, how can this function be utilized by a cell within a Worksheet as a formula?
To utilize an Excel VBA formula as a function, click the “
” sign to edit the formula for that
particular cell and then select “More Functions” from the drop-down function dialog box. A GUI such
=
Search WWH ::




Custom Search