public static ComplexD operator -(double b, ComplexD a) { ComplexD c = -1.0f * a; c.Add(b); return c; }
public static ComplexD operator +(ComplexD a, double b) { ComplexD c = a; c.Add(b); return c; }
public static ComplexD operator -(ComplexD a, double b) { ComplexD c = a; c.Subtract(b); return c; }
public static ComplexD operator *(ComplexD a, ComplexD b) { ComplexD c = a; c.Multiply(b); return c; }
public static ComplexD operator !(ComplexD a) { ComplexD c = a; c.Conjugate(); return c; }
public static ComplexD operator *(double b, ComplexD a) { ComplexD c = a; c.Multiply(b); return c; }
/// <summary> /// Calculates both Square-Roots of a complex number /// </summary> /// <param name="number"></param> /// <returns></returns> public ComplexD[] Sqrt(ComplexD number) { ComplexD res0 = ComplexD.CreateRadial((double)System.Math.Sqrt(number.Norm), number.Argument / 2.0f); ComplexD res1 = ComplexD.CreateRadial((double)System.Math.Sqrt(number.Norm), number.Argument / 2.0f + (double)Constant.Pi); return new ComplexD[2] { res0, res1 }; }
public static ComplexD operator /(ComplexD a, ComplexD b) { ComplexD c = a; c.Divide(b); return c; }
public static ComplexD operator /(ComplexD a, double b) { ComplexD c = a; c.Divide(b); return(c); }
/// <summary> /// Multiplies a complex number with this /// </summary> /// <param name="number"></param> public void Multiply(ComplexD number) { double real = Real; double imag = Imag; Real = real * number.Real - imag * number.Imag; Imag = real * number.Imag + imag * number.Real; }
public static ComplexD operator -(ComplexD a, ComplexD b) { ComplexD c = a; c.Subtract(b); return(c); }
public static ComplexD operator +(ComplexD a, ComplexD b) { ComplexD c = a; c.Add(b); return(c); }
public static ComplexD operator /(double a, ComplexD b) { ComplexD c = a; c.Divide(b); return(c); }
public static ComplexD operator *(ComplexD a, double b) { ComplexD c = a; c.Multiply(b); return(c); }
/// <summary> /// Exponentiates a complex by another /// </summary> /// <returns></returns> public static ComplexD Pow(ComplexD number, ComplexD exponent) { double r = number.Norm; double phi = number.Argument; double a = exponent.Real; double b = exponent.Imag; return ComplexD.CreateRadial((double)System.Math.Exp(System.Math.Log(r) * a - b * phi), a * phi + b * (double)System.Math.Log(r)); }
/// <summary> /// Divides this by a complex number /// </summary> /// <param name="number"></param> public void Divide(ComplexD number) { double t = 1 / number.NormSquared; double real = Real; double imag = Imag; Real = t * (real * number.Real + imag * number.Imag); Imag = t * (imag * number.Real - real * number.Imag); }
/// <summary> /// Calculates e^Complex /// </summary> /// <param name="number"></param> /// <returns></returns> public static ComplexD Exp(ComplexD number) { ComplexD c = ComplexD.Zero; double factor = (double)System.Math.Pow(Constant.E, number.Real); c.Real = factor * (double)System.Math.Cos(number.Imag); c.Imag = factor * (double)System.Math.Sin(number.Imag); return c; }
/// <summary> /// Calculates the n-th Root of a Complex number and returns n Solutions /// </summary> /// <param name="number"></param> /// <param name="order">n</param> /// <returns></returns> public ComplexD[] Root(ComplexD number, int order) { ComplexD[] values = new ComplexD[order]; double phi = number.Argument / 2.0f; double dphi = (double)Constant.PiTimesTwo / (double)order; double r = (double)System.Math.Pow(number.Norm, 1.0f / order); for (int i = 1; i < order; i++) { values[i] = ComplexD.CreateRadial(r, phi + dphi * i); } return values; }
/// <summary> /// Adds a complex number to this /// </summary> /// <param name="number"></param> public void Add(ComplexD number) { Real += number.Real; Imag += number.Imag; }
/// <summary> /// Subtracts a complex number from this /// </summary> /// <param name="number"></param> public void Subtract(ComplexD number) { Real -= number.Real; Imag -= number.Imag; }
/// <summary> /// Exponentiates a complex by a real number /// </summary> /// <returns></returns> public static ComplexD Pow(ComplexD number, double scalar) { number.Pow(scalar); return number; }
/// <summary> /// Natural Logartihm for complex numbers /// </summary> /// <param name="number"></param> /// <returns></returns> public static ComplexD Log(ComplexD number) { return ComplexD.CreateOrthogonal((double)System.Math.Log(number.Norm), number.Argument); }