static void Main(string[] args) { ComplexNumber x = new ComplexNumber(10.5); ComplexNumber y = null; if (y == null && x != null) { y = new ComplexNumber(7, 8.1); ComplexNumber z = x + y; Console.WriteLine(z); // 17,5+i8,1 z -= 20; Console.WriteLine(z); // -2,5+i8,1 z.Real += 13; z.Imaginary -= 8.1; Console.WriteLine(z); // 10,5 if (z == x && z != y) { Console.WriteLine("{0:A}", z - y); // 3,5-i8,1 Console.WriteLine("{0:P}", z - y); // (3,5, -8,1) } } x = y = null; if (x == y) Console.WriteLine("x == y == null"); }
public void Add(ComplexNumber c2) { a += c2.GetReal(); b += c2.GetImaginary(); }
public void Result(ComplexNumber other) { Console.WriteLine($"number3 = {other.A} + {other.B}i"); }
public void Add(ComplexNumber c) { real += c.GetReal(); imaginary += c.GetImaginary(); }
public double Module(ComplexNumber number) { return(Math.Sqrt(number.RealPart * number.RealPart + number.ImaginaryPart * number.ImaginaryPart)); }
public ComplexNumber Product(ComplexNumber number1, ComplexNumber number2) { return(new ComplexNumber(number1.RealPart * number2.RealPart - number1.ImaginaryPart * number2.ImaginaryPart, number1.RealPart * number2.ImaginaryPart + number1.ImaginaryPart * number2.RealPart)); }
public ComplexNumber Division(ComplexNumber number1, ComplexNumber number2) { double ratio = 1 / (Math.Sqrt(number1.RealPart) + Math.Sqrt(number1.ImaginaryPart)); return(new ComplexNumber(ratio * (number2.RealPart * number1.RealPart + number2.ImaginaryPart * number1.ImaginaryPart), ratio * (number2.ImaginaryPart * number1.RealPart - number2.RealPart * number1.ImaginaryPart))); }
public ComplexNumber Subtraction(ComplexNumber number1, ComplexNumber number2) { return(new ComplexNumber(number1.RealPart - number2.ImaginaryPart, number2.RealPart - number2.ImaginaryPart)); }
public ComplexNumber Sum(ComplexNumber number1, ComplexNumber number2) { return(new ComplexNumber(number1.RealPart + number2.ImaginaryPart, number2.RealPart + number2.ImaginaryPart)); }
/// <summary> /// Prints the polar form of the complex number z = r ( cos(theta) + sin(theta); r = |z| and theta = arg(z) /// </summary> /// <param name="z">The complex number to print the polar form of</param> /// <returns>Polar form of the complex number z</returns> public static string PolarFormOutput(ComplexNumber z) { return(z.Modulus + "(Cos(" + z.Argument + ") + Sin(" + z.Argument + "))"); }
/// <summary> /// Returns the complex log of z /// </summary> /// <param name="z">Complex number z</param> /// <returns>Complex log of z</returns> public static ComplexNumber ComplexLog(ComplexNumber z) { return(new ComplexNumber(Log(z.Modulus), z.Argument)); }
/// <summary> /// Compares two complex numbers for equality /// </summary> /// <param name="other">The other complex number to compare to</param> /// <returns>True if both are equal, false otherwise</returns> protected bool Equals(ComplexNumber other) { return(AboutEqual(Real, other.Real) && AboutEqual(Imaginary, other.Imaginary)); }