public static Complex Divide(float a, Complex b) { if (b == 0) { throw new DivideByZeroException(); } Complex result = new Complex(); float aa; float ad; float ba; float bd; float ra; float rd; float x; float y; GreenMath.CartesianToPolar(a, 0, out aa, out ad); GreenMath.CartesianToPolar(b.r, b.i, out ba, out bd); ra = aa - ba; rd = ad / bd; GreenMath.PolarToCartesian(ra, rd, out x, out y); result.r = (float)x; result.i = (float)y; return(result); }
public float Arg() { float angle; GreenMath.CartesianToPolar(r, i, out angle); return(angle); }
public static Complex ln(Complex complex) { Complex result = new Complex(); float a; float d; GreenMath.CartesianToPolar(complex.r, complex.i, out a, out d); result.i = a; result.r = (float)Math.Log(d); return(result); }
public static Complex Normalize(Complex complex) { Complex result = new Complex(); float ra; float rd; GreenMath.CartesianToPolar(complex.r, complex.i, out ra, out rd); GreenMath.PolarToCartesian(ra, 1, out result.r, out result.i); return(complex); }
public static Complex Parse(string stringToParse) { Complex result = new Complex(0, 0); stringToParse = stringToParse.Replace(" ", string.Empty); string[] parts = stringToParse.Split(','); float realPart = GreenMath.ParseFloat(parts[0]); float imaginaryPart = GreenMath.ParseFloat(parts[1]); result.r = realPart; result.i = imaginaryPart; return(result); }
public static Complex Pow(Complex Base, float Exponent) { Complex result = new Complex(); float ra; float rd; float rr; float ri; GreenMath.CartesianToPolar(Base.r, Base.i, out ra, out rd); GreenMath.PolarToCartesian((ra * Exponent), ((float)Math.Pow(rd, Exponent)), out rr, out ri); result.r = rr; result.i = ri; return(result); }
public Complex(float real, float imaginary) { r = real; i = imaginary; float na; float nd; float nx; float ny; GreenMath.CartesianToPolar(r, i, out na, out nd); GreenMath.PolarToCartesian(na, 1, out nx, out ny); normalized = new Complex(); normalized.r = (float)nx; normalized.i = (float)ny; }
public static Complex Pow(float Base, Complex Exponent) { if (Base < 0) { Exponent *= ln(new Complex(Base, 0)); Base = (float)Math.E; } Complex result; Complex realPart = new Complex(); Complex imaginaryPart = new Complex(); realPart.r = (float)Math.Pow(Base, Exponent.r); GreenMath.PolarToCartesian((float)(Exponent.i * Math.Log(Base)), 1, out imaginaryPart.r, out imaginaryPart.i); result = Multiply(realPart, imaginaryPart); return(result); }
public static List <Complex> Roots(Complex complex, int root) { List <Complex> results = new List <Complex>(); for (int j = 1; j <= root; j++) { float r; float i; float a; float d; GreenMath.CartesianToPolar(complex.r, complex.i, out a, out d); Console.WriteLine(a + "\t" + d); GreenMath.PolarToCartesian((a + (float)Math.PI * 2f * (j - 1) / root), (float)Math.Pow(d, 1f / root), out r, out i); results.Add(new Complex(r, i)); } return(results); }