diff --git a/src/Numerics/Complex32.cs b/src/Numerics/Complex32.cs index 9a41fab9..2d08b7c6 100644 --- a/src/Numerics/Complex32.cs +++ b/src/Numerics/Complex32.cs @@ -468,6 +468,29 @@ namespace MathNet.Numerics return result; } + /// + /// Evaluate all square roots of this Complex32. + /// + public Tuple SquareRoots() + { + var principal = SquareRoot(); + return new Tuple(principal, -principal); + } + + /// + /// Evaluate all cubic roots of this Complex32. + /// + public Tuple CubicRoots() + { + float r = (float)Math.Pow(Magnitude, 1d/3d); + float theta = Phase/3; + const float shift = (float)Constants.Pi2/3; + return new Tuple( + FromPolarCoordinates(r, theta), + FromPolarCoordinates(r, theta + shift), + FromPolarCoordinates(r, theta - shift)); + } + /// /// Equality test. /// diff --git a/src/Numerics/ComplexExtensions.cs b/src/Numerics/ComplexExtensions.cs index 4808ff67..eb028e91 100644 --- a/src/Numerics/ComplexExtensions.cs +++ b/src/Numerics/ComplexExtensions.cs @@ -289,6 +289,29 @@ namespace MathNet.Numerics return result; } + /// + /// Evaluate all square roots of this Complex. + /// + public static Tuple SquareRoots(this Complex complex) + { + var principal = SquareRoot(complex); + return new Tuple(principal, -principal); + } + + /// + /// Evaluate all cubic roots of this Complex. + /// + public static Tuple CubicRoots(this Complex complex) + { + var r = Math.Pow(complex.Magnitude, 1d/3d); + var theta = complex.Phase/3; + const double shift = Constants.Pi2/3; + return new Tuple( + Complex.FromPolarCoordinates(r, theta), + Complex.FromPolarCoordinates(r, theta + shift), + Complex.FromPolarCoordinates(r, theta - shift)); + } + /// /// Gets a value indicating whether the Complex32 is zero. ///