Function Math Complex Class

CubicRoot

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

Signature (Visual Basic / VBA)

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

Code Example

    ? CubicRoot(-1, -2, -3, 54, 1)
    2.99999998013179|-1.38196892736712E-14
    ? CubicRoot(-1, -2, -3, 54, 2)
    -2.50000001986822|-3.4278273002005
    ? CubicRoot(-1, -2, -3, 54, 3)
    -2.50000001986821|3.4278273002005

Parameters

Parameter Description
vRootNum The number of the solution that is to be returned, either 1, 2, or 3. Function returns Null if vRootNum if Null or cannot be fixed up to a number that is between 1 and 3.

Notes & Version History

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, vC, and vD See the definition above. Function returns Null if any of the arguments vA, vB, vC, or vD 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.