/** * <u>Berechnen des Tangens der komplexen Zahl</u><br> * * @param comp Komplexe Zahl * @return Rückgabe eines Objektes vom Typ Complex mit Lösung aus tan(<u>z</u>) */ public static Complex tan(Complex comp) { double real, imag; double nn = 1d + Math.pow( Math.tan(comp.getReal()) * Math.tanh(comp.getImag()), 2); // Nenner der Brueche real = (Math.tan(comp.getReal()) * (1 - Math.pow(Math.tanh(comp.getImag()), 2))) / nn; imag = (Math.tanh(comp.getImag()) * (1 + Math.pow(Math.tan(comp.getReal()), 2))) / nn; return new Complex(real, imag); }
public void testScalarMultiplyInf() { Complex z = new Complex(1, 1); Complex w = z.multiply(Double.POSITIVE_INFINITY); assertEquals(w.getReal(), inf, 0); assertEquals(w.getImaginary(), inf, 0); w = z.multiply(Double.NEGATIVE_INFINITY); assertEquals(w.getReal(), inf, 0); assertEquals(w.getImaginary(), inf, 0); }
public void testDivideNaNInf() { Complex z = oneInf.divide(Complex.ONE); assertTrue(Double.isNaN(z.getReal())); assertEquals(inf, z.getImaginary(), 0); z = negInfNegInf.divide(oneNaN); assertTrue(Double.isNaN(z.getReal())); assertTrue(Double.isNaN(z.getImaginary())); z = negInfInf.divide(Complex.ONE); assertTrue(Double.isNaN(z.getReal())); assertTrue(Double.isNaN(z.getImaginary())); }
public void testDivide() { Complex x = new Complex(3.0, 4.0); Complex y = new Complex(5.0, 6.0); Complex z = x.divide(y); assertEquals(39.0 / 61.0, z.getReal(), 1.0e-5); assertEquals(2.0 / 61.0, z.getImaginary(), 1.0e-5); }
public void testMultiply() { Complex x = new Complex(3.0, 4.0); Complex y = new Complex(5.0, 6.0); Complex z = x.multiply(y); assertEquals(-9.0, z.getReal(), 1.0e-5); assertEquals(38.0, z.getImaginary(), 1.0e-5); }
public void testAdd() { Complex x = new Complex(3.0, 4.0); Complex y = new Complex(5.0, 6.0); Complex z = x.add(y); assertEquals(8.0, z.getReal(), 1.0e-5); assertEquals(10.0, z.getImaginary(), 1.0e-5); }
public void testSubtract() { Complex x = new Complex(3.0, 4.0); Complex y = new Complex(5.0, 6.0); Complex z = x.subtract(y); assertEquals(-2.0, z.getReal(), 1.0e-5); assertEquals(-2.0, z.getImaginary(), 1.0e-5); }
public void testScalarMultiply() { Complex x = new Complex(3.0, 4.0); double y = 2.0; Complex z = x.multiply(y); assertEquals(6.0, z.getReal(), 1.0e-5); assertEquals(8.0, z.getImaginary(), 1.0e-5); }
public void testAddNaN() { Complex x = new Complex(3.0, 4.0); Complex z = x.add(Complex.NaN); assertTrue(z.isNaN()); z = new Complex(1, nan); Complex w = x.add(z); assertEquals(w.getReal(), 4.0, 0); assertTrue(Double.isNaN(w.getImaginary())); }
public void testDivideInfinite() { Complex x = new Complex(3, 4); Complex w = new Complex(neginf, inf); assertTrue(x.divide(w).equals(Complex.ZERO)); Complex z = w.divide(x); assertTrue(Double.isNaN(z.getReal())); assertEquals(inf, z.getImaginary(), 0); w = new Complex(inf, inf); z = w.divide(x); assertTrue(Double.isNaN(z.getImaginary())); assertEquals(inf, z.getReal(), 0); w = new Complex(1, inf); z = w.divide(w); assertTrue(Double.isNaN(z.getReal())); assertTrue(Double.isNaN(z.getImaginary())); }
public void testAddInfinite() { Complex x = new Complex(1, 1); Complex z = new Complex(inf, 0); Complex w = x.add(z); assertEquals(w.getImaginary(), 1, 0); assertEquals(inf, w.getReal(), 0); x = new Complex(neginf, 0); assertTrue(Double.isNaN(x.add(z).getReal())); }
public void testMultiplyNaNInf() { Complex z = new Complex(1, 1); Complex w = z.multiply(infOne); assertEquals(w.getReal(), inf, 0); assertEquals(w.getImaginary(), inf, 0); // [MATH-164] assertTrue(new Complex(1, 0).multiply(infInf).equals(Complex.INF)); assertTrue(new Complex(-1, 0).multiply(infInf).equals(Complex.INF)); assertTrue(new Complex(1, 0).multiply(negInfZero).equals(Complex.INF)); w = oneInf.multiply(oneNegInf); assertEquals(w.getReal(), inf, 0); assertEquals(w.getImaginary(), inf, 0); w = negInfNegInf.multiply(oneNaN); assertTrue(Double.isNaN(w.getReal())); assertTrue(Double.isNaN(w.getImaginary())); }
private void ift(Complex[] F, byte[] img, int width, int height) { for (int x = 0; x < height; x++) { for (int y = 0; y < width; y++) { Complex c = new Complex(); for (int u = 0; u < height; u++) { for (int v = 0; v < width; v++) { Complex tmp = Complex.fromPolar( 1, 2.0 * Math.PI * (u * x / (double) height + v * y / (double) width)); c = c.plus(tmp.mul(F[u * width + v])); } } c = c.div(height * width); c = c.mul(Math.pow(-1, (x + y))); if (c.getReal() < 0) c.setReal(0.0); System.out.println(c.getReal()); img[x * width + y] = (byte) (c.getReal()); } } }
public static void main(String args[]) { Complex c1 = new Complex(3, 4); Complex c2 = new Complex(1, 5); Complex add = Complex.add(c1, c2); System.out.println(add.toString()); Complex sub = Complex.sub(c1, c2); System.out.println(sub.getReal() + " + " + sub.getImag() + "i"); Complex mult = Complex.mult(c1, c2); System.out.println(mult.toString()); Complex clone = add.clone(); System.out.println(clone.toString()); }
public TestComplex(Complex other) { this(other.getReal(), other.getImaginary()); }
/** * <u>Subtraktion zweier komplexer Zahlen</u><br> * * @param comp1 1. Komplexe Zahl * @param comp2 2. Komplexe Zahl * @return Rückgabe von neuem Objekt mit Ergebnis aus Subtraktion */ public static Complex sub(Complex comp1, Complex comp2) { return new Complex(comp1.getReal() - comp2.getReal(), comp1.getImag() - comp2.getImag()); }
/** * <u>Subtraktion zweier komplexer Zahlen</u><br> * * @param comp Komplexe Zahl * @return Rückgabe von neuem Objekt mit Ergebnis aus Subtraktion */ public Complex sub(Complex comp) { return new Complex(this.real - comp.getReal(), this.imag - comp.getImag()); }
/** * <u>Addition zweier komplexer Zahlen</u><br> * * @param comp Komplexe Zahl * @return Rückgabe von neuem Objekt mit Ergebnis aus Addition */ public Complex add(Complex comp) { return new Complex(this.real + comp.getReal(), this.imag + comp.getImag()); }
private static boolean closeFourDigit(Complex a, Complex b) { return closeFourDigit(a.getReal(), b.getReal()) && closeFourDigit(a.getImaginary(), b.getImaginary()); }
public Complex multiplyNum(Complex a) { return new Complex(this.real * a.getReal(), this.imag * a.getImag()); }
public Complex addNum(Complex a) { return (Complex) new Complex(this.real + a.getReal(), this.imag + a.getImag()); }
public void evaluateAt(Complex var, Complex res) { res.setValue(var.getImaginary(), var.getReal()); }
public void testNegate() { Complex x = new Complex(3.0, 4.0); Complex z = x.negate(); assertEquals(-3.0, z.getReal(), 1.0e-5); assertEquals(-4.0, z.getImaginary(), 1.0e-5); }
public void testConstructor() { Complex z = new Complex(3.0, 4.0); assertEquals(3.0, z.getReal(), 1.0e-5); assertEquals(4.0, z.getImaginary(), 1.0e-5); }
/** * <u>Berechnen der e-Funktion der komplexen Zahl</u><br> * * @param comp Komplexe Zahl * @return Rückgabe eines Objektes vom Typ Complex mit Lösung aus exp(<u>z</u>) */ public static Complex exp(Complex comp) { return new Complex( Math.cos(comp.getImag()) * (Math.sinh(comp.getReal()) + Math.cosh(comp.getReal())), Math.sin(comp.getImag()) * (Math.cosh(comp.getReal()) + Math.sinh(comp.getReal()))); }
/** * <u>Berechnen der konjugierten komplexen Zahl</u><br> * * @param comp Komplexe Zahl * * @return Rückgabe eines Objektes vom Typ Complex mit Lösung aus conj(<u>z</u>) */ public Complex conj(Complex comp) { return new Complex(comp.getReal(), -comp.getImag()); }
public static void testValues() { Complex c = new Complex(2, 3); System.out.println("(" + c + ")" + " = " + c.getReal()); System.out.println("(" + c + ")" + " = " + c.getComplex() + "i"); System.out.println(); }