Ejemplo n.º 1
0
  public Complex acos() {
    Complex result;
    double tempRe, tempIm;

    //  acos(z)  =  -i * log( z + i * sqrt(1 - z*z) )

    tempRe = 1.0 - ((re * re) - (im * im));
    tempIm = 0.0 - ((re * im) + (im * re));

    result = new Complex(tempRe, tempIm);
    result = result.sqrt();

    tempRe = -result.im;
    tempIm = result.re;

    result.re = re + tempRe;
    result.im = im + tempIm;

    tempRe = Math.log(result.abs());
    tempIm = result.arg();

    result.re = tempIm;
    result.im = -tempRe;

    return result;
  }
Ejemplo n.º 2
0
  public Complex asinh() {
    Complex result;
    //  asinh(z)  =  log(z + sqrt(z*z + 1))

    result = new Complex(((re * re) - (im * im)) + 1, (re * im) + (im * re));

    result = result.sqrt();

    result.re += re;
    result.im += im;

    double temp = result.arg();
    result.re = Math.log(result.abs());
    result.im = temp;

    return result;
  }
Ejemplo n.º 3
0
  public Complex asin() {
    Complex result;
    double tempRe, tempIm;

    //  asin(z)  =  -i * log(i*z + sqrt(1 - z*z))

    tempRe = 1.0 - ((re * re) - (im * im));
    tempIm = 0.0 - ((re * im) + (im * re));

    result = new Complex(tempRe, tempIm);
    result = result.sqrt();

    result.re += -im;
    result.im += re;

    tempRe = Math.log(result.abs());
    tempIm = result.arg();

    result.re = tempIm;
    result.im = -tempRe;

    return result;
  }
Ejemplo n.º 4
0
  // sample client for testing
  public static void main(String[] args) {
    Complex a = new Complex(5.0, 6.0);
    Complex b = new Complex(-3.0, 4.0);

    System.out.println("a            = " + a);
    System.out.println("b            = " + b);
    System.out.println("Re(a)        = " + a.re());
    System.out.println("Im(a)        = " + a.im());
    System.out.println("b + a        = " + b.plus(a));
    System.out.println("a - b        = " + a.minus(b));
    System.out.println("a * b        = " + a.times(b));
    System.out.println("b * a        = " + b.times(a));
    System.out.println("a / b        = " + a.divides(b));
    System.out.println("(a / b) * b  = " + a.divides(b).times(b));
    System.out.println("conj(a)      = " + a.conjugate());
    System.out.println("|a|          = " + a.abs());
    System.out.println("tan(a)       = " + a.tan());
  }
Ejemplo n.º 5
0
  public Complex atanh() {
    //  atanh(z)  =  1/2 * log( (1+z)/(1-z) )

    double tempRe, tempIm;
    Complex result = new Complex(1.0 + re, im);

    tempRe = 1.0 - re;
    tempIm = -im;

    result = result.div(new Complex(tempRe, tempIm));

    tempRe = Math.log(result.abs());
    tempIm = result.arg();

    result.re = 0.5 * tempRe;
    result.im = 0.5 * tempIm;

    return result;
  }
Ejemplo n.º 6
0
  public Complex atan() {
    // atan(z) = -i/2 * log((i-z)/(i+z))

    double tempRe, tempIm;
    Complex result = new Complex(-re, 1.0 - im);

    tempRe = re;
    tempIm = 1.0 + im;

    result = result.div(new Complex(tempRe, tempIm));

    tempRe = Math.log(result.abs());
    tempIm = result.arg();

    result.re = 0.5 * tempIm;
    result.im = -0.5 * tempRe;

    return result;
  }
Ejemplo n.º 7
0
 @Override
 public Complex add(Complex other) {
   return Complex.rectangular(this.re() + other.re(), this.im() + other.im()).toPolar();
 }
Ejemplo n.º 8
0
 public Complex subtract(Complex a) {
   Complex c2 = new Complex(0, 0);
   c2.re = re - a.re;
   c2.im = im - a.im;
   return c2;
 }
Ejemplo n.º 9
0
 public Complex add(Complex a) {
   Complex c1 = new Complex(0, 0);
   c1.re = re + a.re;
   c1.im = im + a.im;
   return c1;
 }