/** * Computes the N<sup>th</sup> root of a complex number. There are * N distinct N<sup>th</sup> roots. * * @param a Complex number * @param N The root's magnitude * @param k Specifies which root. 0 ≤ k < N * @param result Computed root */ public static void root(Complex_F64 a, int N, int k, Complex_F64 result) { double r = a.getMagnitude(); double theta = Math.Atan2(a.imaginary, a.real); r = Math.Pow(r, 1.0 / N); theta = (theta + 2.0 * k * UtilEjml.PI) / N; result.real = r * (double)Math.Cos(theta); result.imaginary = r * (double)Math.Sin(theta); }
/** * Computes the square root of the complex number. * * @param input Input complex number. * @param root Output. The square root of the input */ public static void sqrt(Complex_F64 input, Complex_F64 root) { double r = input.getMagnitude(); double a = input.real; root.real = Math.Sqrt((r + a) / 2.0); root.imaginary = Math.Sqrt((r - a) / 2.0); if (input.imaginary < 0) { root.imaginary = -root.imaginary; } }
/** * <p> * Converts a complex number into polar notation. * </p> * * @param input Standard notation * @param output Polar notation */ public static void convert(Complex_F64 input, ComplexPolar_F64 output) { output.r = input.getMagnitude(); output.theta = Math.Atan2(input.imaginary, input.real); }