Package org.jamesii.core.math.complex

Examples of org.jamesii.core.math.complex.Complex


  /**
   * Test negate.
   */
  public void testNegate() {
    ComplexArray1D a =
        new ComplexArray1D(new Complex[] { new Complex(1, 4),
            new Complex(-2, 3), new Complex(-1, -3), new Complex() });

    ComplexArray1D b = new ComplexArray1D(a.toComplexArray());

    for (int i = 0; i < a.getLength(); i++) {
      a.negate(i);
View Full Code Here


  /**
   * Test conjugate exceptions.
   */
  public void testConjugateExceptions() {
    ComplexArray1D a = new ComplexArray1D(new Complex[] { new Complex(1, 1) });

    try {
      a.conjugate(-1);
      fail();
    } catch (IndexOutOfBoundsException e) {
      assertTrue(true);
    } catch (Exception e) {
      fail();
    }
    try {
      a.conjugate(5);
      fail();
    } catch (IndexOutOfBoundsException e) {
      assertTrue(true);
    } catch (Exception e) {
      fail();
    }

    // check for side-effects. Nothing should have changed!
    assertTrue(a.getComplex(0).equals(new Complex(1, 1)));
  }
View Full Code Here

  /**
   * Test conjugate.
   */
  public void testConjugate() {
    ComplexArray1D a =
        new ComplexArray1D(new Complex[] { new Complex(1, 4),
            new Complex(-2, 3), new Complex(-1, -3), new Complex() });

    ComplexArray1D b = new ComplexArray1D(a.toComplexArray());

    for (int i = 0; i < a.getLength(); i++) {
      a.conjugate(i);
View Full Code Here

  /**
   * Test add exceptions.
   */
  public void testAddExceptions() {
    ComplexArray1D a = new ComplexArray1D(new Complex[] { new Complex(1, 1) });

    // testing add(int, double, double, double, double)
    try {
      a.add(-1, 2d, 3d, 1d, 2d);
      fail();
    } catch (IndexOutOfBoundsException e) {
      assertTrue(true);
    } catch (Exception e) {
      fail();
    }
    try {
      a.add(5, 5d, 4d, 2d, 1d);
      fail();
    } catch (IndexOutOfBoundsException e) {
      assertTrue(true);
    } catch (Exception e) {
      fail();
    }

    // testing add(int, int, double, double)
    try {
      a.add(-1, 0, 1d, 2d);
      fail();
    } catch (IndexOutOfBoundsException e) {
      assertTrue(true);
    } catch (Exception e) {
      fail();
    }
    try {
      a.add(5, 0, 1d, 1d);
      fail();
    } catch (IndexOutOfBoundsException e) {
      assertTrue(true);
    } catch (Exception e) {
      fail();
    }
    try {
      a.add(0, -2, 2d, 3d);
      fail();
    } catch (IndexOutOfBoundsException e) {
      assertTrue(true);
    } catch (Exception e) {
      fail();
    }
    try {
      a.add(0, 10, 3d, 2d);
      fail();
    } catch (IndexOutOfBoundsException e) {
      assertTrue(true);
    } catch (Exception e) {
      fail();
    }

    // testing add(int, int, int)
    try {
      a.add(-1, 0, 0);
      fail();
    } catch (IndexOutOfBoundsException e) {
      assertTrue(true);
    } catch (Exception e) {
      fail();
    }
    try {
      a.add(5, 0, 0);
      fail();
    } catch (IndexOutOfBoundsException e) {
      assertTrue(true);
    } catch (Exception e) {
      fail();
    }
    try {
      a.add(0, -2, 0);
      fail();
    } catch (IndexOutOfBoundsException e) {
      assertTrue(true);
    } catch (Exception e) {
      fail();
    }
    try {
      a.add(0, 10, 0);
      fail();
    } catch (IndexOutOfBoundsException e) {
      assertTrue(true);
    } catch (Exception e) {
      fail();
    }
    try {
      a.add(0, 0, -1);
      fail();
    } catch (IndexOutOfBoundsException e) {
      assertTrue(true);
    } catch (Exception e) {
      fail();
    }
    try {
      a.add(0, 0, 10);
      fail();
    } catch (IndexOutOfBoundsException e) {
      assertTrue(true);
    } catch (Exception e) {
      fail();
    }

    // check for side-effects. Nothing should have changed!
    assertTrue(a.getComplex(0).equals(new Complex(1, 1)));
  }
View Full Code Here

  /**
   * Test add.
   */
  public void testAdd() {
    ComplexArray1D a =
        new ComplexArray1D(new Complex[] { new Complex(1, 2),
            new Complex(3, 4), new Complex(5, 6) });

    // initial tests ... we can't have too many of them :)
    assertTrue(a.getComplex(0).equals(new Complex(1, 2)));
    assertTrue(a.getComplex(1).equals(new Complex(3, 4)));
    assertTrue(a.getComplex(2).equals(new Complex(5, 6)));

    // testing add(int, int, int)
    a.add(0, 1, 2);
    assertTrue(a.getComplex(0).equals(new Complex(8, 10)));
    assertTrue(a.getComplex(1).equals(new Complex(3, 4)));
    assertTrue(a.getComplex(2).equals(new Complex(5, 6)));

    // testing add(int, int, double, double)
    a.add(0, 1, 1.5, -4.75);
    assertTrue(a.getComplex(0).equals(new Complex(4.5, -.75)));
    assertTrue(a.getComplex(1).equals(new Complex(3, 4)));
    assertTrue(a.getComplex(2).equals(new Complex(5, 6)));

    // testing add(int, double, double, double, double)
    a.add(2, 4, 2, -1, -8);
    assertTrue(a.getComplex(0).equals(new Complex(4.5, -.75)));
    assertTrue(a.getComplex(1).equals(new Complex(3, 4)));
    assertTrue(a.getComplex(2).equals(new Complex(3, -6)));
  }
View Full Code Here

  /**
   * Test subtract exceptions.
   */
  public void testSubtractExceptions() {
    ComplexArray1D a = new ComplexArray1D(new Complex[] { new Complex(1, 1) });

    // testing subtract(int, double, double, double, double)
    try {
      a.subtract(-1, 3d, 4d, 1d, 2d);
      fail();
    } catch (IndexOutOfBoundsException e) {
      assertTrue(true);
    } catch (Exception e) {
      fail();
    }
    try {
      a.subtract(5, 2d, 3d, 2d, 1d);
      fail();
    } catch (IndexOutOfBoundsException e) {
      assertTrue(true);
    } catch (Exception e) {
      fail();
    }

    // testing subtract(int, int, double, double)
    try {
      a.subtract(-1, 0, 1d, 1d);
      fail();
    } catch (IndexOutOfBoundsException e) {
      assertTrue(true);
    } catch (Exception e) {
      fail();
    }
    try {
      a.subtract(5, 0, 1d, 1d);
      fail();
    } catch (IndexOutOfBoundsException e) {
      assertTrue(true);
    } catch (Exception e) {
      fail();
    }
    try {
      a.subtract(0, -2, 1d, 1d);
      fail();
    } catch (IndexOutOfBoundsException e) {
      assertTrue(true);
    } catch (Exception e) {
      fail();
    }
    try {
      a.subtract(0, 10, 1d, 1d);
      fail();
    } catch (IndexOutOfBoundsException e) {
      assertTrue(true);
    } catch (Exception e) {
      fail();
    }

    // testing subtract(int, double, double, int)
    try {
      a.subtract(-1, 1d, 1d, 0);
      fail();
    } catch (IndexOutOfBoundsException e) {
      assertTrue(true);
    } catch (Exception e) {
      fail();
    }
    try {
      a.subtract(5, 1d, 1d, 0);
      fail();
    } catch (IndexOutOfBoundsException e) {
      assertTrue(true);
    } catch (Exception e) {
      fail();
    }
    try {
      a.subtract(0, 1d, 1d, -2);
      fail();
    } catch (IndexOutOfBoundsException e) {
      assertTrue(true);
    } catch (Exception e) {
      fail();
    }
    try {
      a.subtract(0, 1d, 1d, 10);
      fail();
    } catch (IndexOutOfBoundsException e) {
      assertTrue(true);
    } catch (Exception e) {
      fail();
    }

    // testing subtract(int, int, int)
    try {
      a.subtract(-1, 0, 0);
      fail();
    } catch (IndexOutOfBoundsException e) {
      assertTrue(true);
    } catch (Exception e) {
      fail();
    }
    try {
      a.add(5, 0, 0);
      fail();
    } catch (IndexOutOfBoundsException e) {
      assertTrue(true);
    } catch (Exception e) {
      fail();
    }
    try {
      a.add(0, -2, 0);
      fail();
    } catch (IndexOutOfBoundsException e) {
      assertTrue(true);
    } catch (Exception e) {
      fail();
    }
    try {
      a.add(0, 10, 0);
      fail();
    } catch (IndexOutOfBoundsException e) {
      assertTrue(true);
    } catch (Exception e) {
      fail();
    }
    try {
      a.add(0, 0, -1);
      fail();
    } catch (IndexOutOfBoundsException e) {
      assertTrue(true);
    } catch (Exception e) {
      fail();
    }
    try {
      a.add(0, 0, 10);
      fail();
    } catch (IndexOutOfBoundsException e) {
      assertTrue(true);
    } catch (Exception e) {
      fail();
    }

    // check for side-effects. Nothing should have changed!
    assertTrue(a.getComplex(0).equals(new Complex(1, 1)));
  }
View Full Code Here

  /**
   * Test subtract.
   */
  public void testSubtract() {
    ComplexArray1D a =
        new ComplexArray1D(new Complex[] { new Complex(1, 2),
            new Complex(3, 4), new Complex(5, 6) });

    // initial tests ... we can't have too many of them :)
    assertTrue(a.getComplex(0).equals(new Complex(1, 2)));
    assertTrue(a.getComplex(1).equals(new Complex(3, 4)));
    assertTrue(a.getComplex(2).equals(new Complex(5, 6)));

    // testing subtract(int, int, int)
    a.subtract(0, 1, 2);
    assertTrue(a.getComplex(0).equals(new Complex(-2, -2)));
    assertTrue(a.getComplex(1).equals(new Complex(3, 4)));
    assertTrue(a.getComplex(2).equals(new Complex(5, 6)));

    // testing subtract(int, int, double, double)
    a.subtract(0, 1, 1.5, -4.75);
    assertTrue(a.getComplex(0).equals(new Complex(1.5, 8.75)));
    assertTrue(a.getComplex(1).equals(new Complex(3, 4)));
    assertTrue(a.getComplex(2).equals(new Complex(5, 6)));

    // testing subtract(int, double, double, int)
    a.subtract(0, 1.5, -4.75, 2);
    assertTrue(a.getComplex(0).equals(new Complex(-3.5, -10.75)));
    assertTrue(a.getComplex(1).equals(new Complex(3, 4)));
    assertTrue(a.getComplex(2).equals(new Complex(5, 6)));

    // testing subtract(int, double, double, double, double)
    a.subtract(2, 4, 2, -1, -8);
    assertTrue(a.getComplex(0).equals(new Complex(-3.5, -10.75)));
    assertTrue(a.getComplex(1).equals(new Complex(3, 4)));
    assertTrue(a.getComplex(2).equals(new Complex(5, 10)));
  }
View Full Code Here

  /**
   * Test multiply exceptions.
   */
  public void testMultiplyExceptions() {
    ComplexArray1D a = new ComplexArray1D(new Complex[] { new Complex(1, 1) });

    // testing multiply(int, double, double, double, double)
    try {
      a.multiply(-1, 2d, 3d, 1d, 2d);
      fail();
    } catch (IndexOutOfBoundsException e) {
      assertTrue(true);
    } catch (Exception e) {
      fail();
    }
    try {
      a.multiply(5, 5d, 4d, 2d, 1d);
      fail();
    } catch (IndexOutOfBoundsException e) {
      assertTrue(true);
    } catch (Exception e) {
      fail();
    }

    // testing multiply(int, int, double, double)
    try {
      a.multiply(-1, 0, 1d, 2d);
      fail();
    } catch (IndexOutOfBoundsException e) {
      assertTrue(true);
    } catch (Exception e) {
      fail();
    }
    try {
      a.multiply(5, 0, 1d, 1d);
      fail();
    } catch (IndexOutOfBoundsException e) {
      assertTrue(true);
    } catch (Exception e) {
      fail();
    }
    try {
      a.multiply(0, -2, 2d, 3d);
      fail();
    } catch (IndexOutOfBoundsException e) {
      assertTrue(true);
    } catch (Exception e) {
      fail();
    }
    try {
      a.multiply(0, 10, 3d, 2d);
      fail();
    } catch (IndexOutOfBoundsException e) {
      assertTrue(true);
    } catch (Exception e) {
      fail();
    }

    // testing multiply(int, int, int)
    try {
      a.multiply(-1, 0, 0);
      fail();
    } catch (IndexOutOfBoundsException e) {
      assertTrue(true);
    } catch (Exception e) {
      fail();
    }
    try {
      a.multiply(5, 0, 0);
      fail();
    } catch (IndexOutOfBoundsException e) {
      assertTrue(true);
    } catch (Exception e) {
      fail();
    }
    try {
      a.multiply(0, -2, 0);
      fail();
    } catch (IndexOutOfBoundsException e) {
      assertTrue(true);
    } catch (Exception e) {
      fail();
    }
    try {
      a.multiply(0, 10, 0);
      fail();
    } catch (IndexOutOfBoundsException e) {
      assertTrue(true);
    } catch (Exception e) {
      fail();
    }
    try {
      a.multiply(0, 0, -1);
      fail();
    } catch (IndexOutOfBoundsException e) {
      assertTrue(true);
    } catch (Exception e) {
      fail();
    }
    try {
      a.multiply(0, 0, 10);
      fail();
    } catch (IndexOutOfBoundsException e) {
      assertTrue(true);
    } catch (Exception e) {
      fail();
    }

    // check for side-effects. Nothing should have changed!
    assertTrue(a.getComplex(0).equals(new Complex(1, 1)));
  }
View Full Code Here

  /**
   * Test multiply.
   */
  public void testMultiply() {
    ComplexArray1D a =
        new ComplexArray1D(new Complex[] { new Complex(1, 2),
            new Complex(3, 4), new Complex(5, 6) });

    // initial tests ... we can't have too many of them :)
    assertTrue(a.getComplex(0).equals(new Complex(1, 2)));
    assertTrue(a.getComplex(1).equals(new Complex(3, 4)));
    assertTrue(a.getComplex(2).equals(new Complex(5, 6)));

    // testing multiply(int, int, int)
    a.multiply(0, 1, 2);
    assertTrue(a.getComplex(0).equals(new Complex(-9, 38)));
    assertTrue(a.getComplex(1).equals(new Complex(3, 4)));
    assertTrue(a.getComplex(2).equals(new Complex(5, 6)));

    // testing multiply(int, int, double, double)
    a.multiply(0, 1, 1.5, -4.75);
    assertTrue(a.getComplex(0).equals(new Complex(23.5, -8.25)));
    assertTrue(a.getComplex(1).equals(new Complex(3, 4)));
    assertTrue(a.getComplex(2).equals(new Complex(5, 6)));

    // testing multiply(int, double, double, double, double)
    a.multiply(2, 4, 2, -1, -8);
    assertTrue(a.getComplex(0).equals(new Complex(23.5, -8.25)));
    assertTrue(a.getComplex(1).equals(new Complex(3, 4)));
    assertTrue(a.getComplex(2).equals(new Complex(12, -34)));
  }
View Full Code Here

    // combine
    Complex[] y = new Complex[n];
    for (int k = 0; k < n / 2; k++) {
      double kth = -2 * k * Math.PI / n;
      Complex wk = new Complex(Math.cos(kth), Math.sin(kth));
      y[k] = q[k].add(wk.multiply(r[k]));
      y[k + n / 2] = q[k].subtract(wk.multiply(r[k]));
    }
    return y;
  }
View Full Code Here

TOP

Related Classes of org.jamesii.core.math.complex.Complex

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.