Example #1
0
 /**
  * add:(复数的乘法)
  *
  * @param 设定文件
  * @return void 返回复数
  * @throws
  * @since CodingExample Ver 1.1
  */
 public Complex mul(Complex b) {
   //		(a+bi) * (c + di) = ac + adi + bci + bd(i*i) = (ac-bd) + * (ad+bc)i
   Complex temp = new Complex();
   temp.real = this.real * b.real - this.im * b.im;
   temp.im = this.real * b.im + this.im + b.real;
   return temp;
 }
  public static void main(String args[]) {

    // use the first constructor
    Complex x = new Complex();
    x.real = 1.0;
    x.imag = 2.0;

    // use the second constructor
    Complex y = new Complex(3.0, 4.0);

    System.out.println(abs(y));

    conjugate(x);
    printComplex(x);
    printComplex(y);

    Complex s = add(x, y);
    printComplex(s);
  }
Example #3
0
 /**
  * add:(复数的减法)
  *
  * @param 设定文件
  * @return void 返回复数
  * @throws
  * @since CodingExample Ver 1.1
  */
 public Complex sub(Complex b) {
   Complex temp = new Complex();
   temp.real = this.real - b.real;
   temp.im = this.im - b.im;
   return temp;
 }
Example #4
0
 /**
  * add:(复数的加法)
  *
  * @param 设定文件
  * @return void 返回复数
  * @throws
  * @since CodingExample Ver 1.1
  */
 public Complex add(Complex b) {
   Complex temp = new Complex();
   temp.real = this.real + b.real;
   temp.im = this.im + b.im;
   return temp;
 }