コード例 #1
0
ファイル: Program.cs プロジェクト: satanaehl/.Net
        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");
        }
コード例 #2
0
 public void Add(ComplexNumber c2)
 {
     a += c2.GetReal();
     b += c2.GetImaginary();
 }
コード例 #3
0
 public void Result(ComplexNumber other)
 {
     Console.WriteLine($"number3 = {other.A} + {other.B}i");
 }
コード例 #4
0
 public void Add(ComplexNumber c)
 {
     real      += c.GetReal();
     imaginary += c.GetImaginary();
 }
コード例 #5
0
 public double Module(ComplexNumber number)
 {
     return(Math.Sqrt(number.RealPart * number.RealPart + number.ImaginaryPart * number.ImaginaryPart));
 }
コード例 #6
0
 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));
 }
コード例 #7
0
        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)));
        }
コード例 #8
0
 public ComplexNumber Subtraction(ComplexNumber number1, ComplexNumber number2)
 {
     return(new ComplexNumber(number1.RealPart - number2.ImaginaryPart, number2.RealPart - number2.ImaginaryPart));
 }
コード例 #9
0
 public ComplexNumber Sum(ComplexNumber number1, ComplexNumber number2)
 {
     return(new ComplexNumber(number1.RealPart + number2.ImaginaryPart, number2.RealPart + number2.ImaginaryPart));
 }
コード例 #10
0
 /// <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 + "))");
 }
コード例 #11
0
 /// <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));
 }
コード例 #12
0
 /// <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));
 }