Browse Source

Complex: routines to get all square and cubic roots of a complex number

provider
Christoph Ruegg 13 years ago
parent
commit
abadd146ff
  1. 23
      src/Numerics/Complex32.cs
  2. 23
      src/Numerics/ComplexExtensions.cs

23
src/Numerics/Complex32.cs

@ -468,6 +468,29 @@ namespace MathNet.Numerics
return result; return result;
} }
/// <summary>
/// Evaluate all square roots of this <c>Complex32</c>.
/// </summary>
public Tuple<Complex32, Complex32> SquareRoots()
{
var principal = SquareRoot();
return new Tuple<Complex32, Complex32>(principal, -principal);
}
/// <summary>
/// Evaluate all cubic roots of this <c>Complex32</c>.
/// </summary>
public Tuple<Complex32, Complex32, Complex32> CubicRoots()
{
float r = (float)Math.Pow(Magnitude, 1d/3d);
float theta = Phase/3;
const float shift = (float)Constants.Pi2/3;
return new Tuple<Complex32, Complex32, Complex32>(
FromPolarCoordinates(r, theta),
FromPolarCoordinates(r, theta + shift),
FromPolarCoordinates(r, theta - shift));
}
/// <summary> /// <summary>
/// Equality test. /// Equality test.
/// </summary> /// </summary>

23
src/Numerics/ComplexExtensions.cs

@ -289,6 +289,29 @@ namespace MathNet.Numerics
return result; return result;
} }
/// <summary>
/// Evaluate all square roots of this <c>Complex</c>.
/// </summary>
public static Tuple<Complex, Complex> SquareRoots(this Complex complex)
{
var principal = SquareRoot(complex);
return new Tuple<Complex, Complex>(principal, -principal);
}
/// <summary>
/// Evaluate all cubic roots of this <c>Complex</c>.
/// </summary>
public static Tuple<Complex, Complex, Complex> 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, Complex, Complex>(
Complex.FromPolarCoordinates(r, theta),
Complex.FromPolarCoordinates(r, theta + shift),
Complex.FromPolarCoordinates(r, theta - shift));
}
/// <summary> /// <summary>
/// Gets a value indicating whether the <c>Complex32</c> is zero. /// Gets a value indicating whether the <c>Complex32</c> is zero.
/// </summary> /// </summary>

Loading…
Cancel
Save