/** * 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_F32 a, int N, int k, Complex_F32 result) { float r = a.getMagnitude(); float theta = (float)Math.Atan2(a.imaginary, a.real); r = (float)Math.Pow(r, 1.0f / N); theta = (theta + 2.0f * k * UtilEjml.F_PI) / N; result.real = r * (float)Math.Cos(theta); result.imaginary = r * (float)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_F32 input, Complex_F32 root) { float r = input.getMagnitude(); float a = input.real; root.real = (float)Math.Sqrt((r + a) / 2.0f); root.imaginary = (float)Math.Sqrt((r - a) / 2.0f); 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_F32 input, ComplexPolar_F32 output) { output.r = input.getMagnitude(); output.theta = (float)Math.Atan2(input.imaginary, input.real); }