示例#1
0
        public static ComplexNumbers operator -(ComplexNumbers num1_, double num2_)
        {
            double         real = num1_.real - num2_;
            double         img  = num1_.img;
            ComplexNumbers temp = new ComplexNumbers(real, img);

            return(temp);
        }
示例#2
0
        public static ComplexNumbers operator *(ComplexNumbers num1_, double num2_)
        {
            double         real = num1_.real * num2_;//(a + bi) * (c + di) = (ac+bd) + (ad+bc)i
            double         img  = num1_.img * num2_;
            ComplexNumbers temp = new ComplexNumbers(real, img);

            return(temp);
        }
示例#3
0
        public static ComplexNumbers operator +(ComplexNumbers num1_, ComplexNumbers num2_)
        {
            double         real = num1_.real + num2_.real;
            double         img  = num1_.img + num2_.img;
            ComplexNumbers temp = new ComplexNumbers(real, img);

            return(temp);
        }
示例#4
0
 public static ComplexNumbers operator /(ComplexNumbers num1_, ComplexNumbers num2_)
 {
     if (num2_.real == 0 && num2_.img == 0)
     {
         throw new DivideByZeroException();
     }
     else
     {
         double         dividend  = num2_.real * num2_.real + num2_.img * num2_.img;//c^2 + d^2
         ComplexNumbers conjugate = new ComplexNumbers(num2_.real, -num2_.img);
         ComplexNumbers temp      = (num1_ * conjugate) / dividend;
         return(temp);
     }
 }
示例#5
0
 public static ComplexNumbers operator /(ComplexNumbers num1_, double num2_)
 {
     if (num2_ == 0)
     {
         throw new DivideByZeroException();
     }
     else
     {
         double         real = num1_.real / num2_;
         double         img  = num1_.img / num2_;
         ComplexNumbers temp = new ComplexNumbers(real, img);
         return(temp);
     }
 }
示例#6
0
 public static ComplexNumbers operator /(double num1_, ComplexNumbers num2_)
 {
     if (num2_.real == 0 && num2_.img == 0)
     {
         throw new DivideByZeroException();
     }
     else
     {
         double         dividend = num2_.real * num2_.real + num2_.img * num2_.img; //a^2 + b^2
         double         real     = (num1_ * num2_.real) / dividend;                 //(m * a) / (a^2 + b^2)
         double         img      = (num1_ * num2_.img) / dividend;                  //(m * -bi) / (a^2 + b^2)
         ComplexNumbers temp     = new ComplexNumbers(real, img);
         return(temp);
     }
 }
示例#7
0
        public static ComplexNumbers operator ^(ComplexNumbers num_, int index_)
        {
            ComplexNumbers temp = num_;

            if (index_ > 0)
            {
                for (int i = 0; i < index_ - 1; i++)
                {
                    temp *= num_;
                }
                return(temp);//power on integer by muiltyply
            }
            else if (index_ == 0)
            {
                return(new ComplexNumbers(1, 0));
            }
            else
            {
                temp = temp ^ (-index_);
                temp = 1 / temp;
                return(temp);
            }
        }
示例#8
0
 public static void show(ComplexNumbers num)
 {
     num.Show();
 }