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; }
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; }
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; }
// 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()); }
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; }
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; }
@Override public Complex add(Complex other) { return Complex.rectangular(this.re() + other.re(), this.im() + other.im()).toPolar(); }
public Complex subtract(Complex a) { Complex c2 = new Complex(0, 0); c2.re = re - a.re; c2.im = im - a.im; return c2; }
public Complex add(Complex a) { Complex c1 = new Complex(0, 0); c1.re = re + a.re; c1.im = im + a.im; return c1; }