<-- Previous || Up || Next -->

Quadratic Root Function
Math Complex Class

Public Function QuadraticRoot( _
      ByVal vA As Variant _
    , ByVal vB As Variant _
    , ByVal vC As Variant _
    , ByVal vRootNum As Variant _
    ) As Variant

"Root Of Quadratic Equation"
Returns one of the three roots of the cubic equation.
Solves the equation A X^2 + B X + C = 0 for X.
Real solutions are returned as a numeric value and complex solutions are returned as a complex number string.

Examples:
    QuadraticRoot(-2, -2, 3, 1) = -1.82287565553229
    QuadraticRoot(-2, -2, 3, 2) = 0.822875655532295
    QuadraticRoot(-2, -3, -4, 1) = "-0.75|1.19895788082818"
    QuadraticRoot(-2, -3, -4, 2) = "-0.75|-1.19895788082818"
See also:
    QuadraticExpr Function
    CubicRoot function
    QuadraticRootSample Subroutine
    QuadraticRootBenchmark Subroutine
Note: In many cases you will have to accept a complex number as the return value then round that number off to zero if it approximately equal to zero.
vA, vB, and vC: See the definition above. Function returns Null if any of the arguments vA, vB, or vC are Null or cannot be fixed up to real or complex numbers (as defined by the ComplexStringToReals function). Complex numbers are represented within strings as "R|I" where R is the real part and I is the imaginary part.
vRootNum: The number of the solution that is to be returned, either 1 or 2. Function returns Null if vRootNum if Null or cannot be fixed up to a number that is either 1 or 2.

Solution #1:

    (-vB - Sqr(vB ^ 2 - 4 * vA * vC)) / (2 * vA)
Solution #2:
    (-vB + Sqr(vB ^ 2 - 4 * vA * vC)) / (2 * vA)

Copyright 1996-1999 Entisoft
Entisoft Tools is a trademark of Entisoft.