Package org.apache.commons.math.complex

Examples of org.apache.commons.math.complex.Complex


    /**
     * Test of solver for the quintic function using solveAll().
     */
    public void testQuinticFunction2() throws MathException {
        double initial = 0.0, tolerance;
        Complex expected, result[];

        // p(x) = x^5 + 4x^3 + x^2 + 4 = (x+1)(x^2-x+1)(x^2+4)
        double coefficients[] = { 4.0, 0.0, 1.0, 4.0, 0.0, 1.0 };
        LaguerreSolver solver = new LaguerreSolver();
        result = solver.solveAll(coefficients, initial);

        expected = new Complex(0.0, -2.0);
        tolerance = Math.max(solver.getAbsoluteAccuracy(),
                    Math.abs(expected.abs() * solver.getRelativeAccuracy()));
        TestUtils.assertContains(result, expected, tolerance);

        expected = new Complex(0.0, 2.0);
        tolerance = Math.max(solver.getAbsoluteAccuracy(),
                    Math.abs(expected.abs() * solver.getRelativeAccuracy()));
        TestUtils.assertContains(result, expected, tolerance);

        expected = new Complex(0.5, 0.5 * Math.sqrt(3.0));
        tolerance = Math.max(solver.getAbsoluteAccuracy(),
                    Math.abs(expected.abs() * solver.getRelativeAccuracy()));
        TestUtils.assertContains(result, expected, tolerance);

        expected = new Complex(-1.0, 0.0);
        tolerance = Math.max(solver.getAbsoluteAccuracy(),
                    Math.abs(expected.abs() * solver.getRelativeAccuracy()));
        TestUtils.assertContains(result, expected, tolerance);

        expected = new Complex(0.5, -0.5 * Math.sqrt(3.0));
        tolerance = Math.max(solver.getAbsoluteAccuracy(),
                    Math.abs(expected.abs() * solver.getRelativeAccuracy()));
        TestUtils.assertContains(result, expected, tolerance);
    }
View Full Code Here


 

  public static ComplexVector c(double... d){
    ComplexArrayVector.Builder builder = new ComplexArrayVector.Builder();
    for(double di : d){
        builder.add(new Complex(di,0));
    }
      return builder.build();
  }
View Full Code Here

    }
      return builder.build();
  }
 
  public static Complex complex(double x,double y){
    return new Complex(x,y);
  }
View Full Code Here

      throw new RuntimeException(e);
    }
  }

  protected Complex complex(double real) {
    return new Complex(real, 0);
  }
View Full Code Here

  protected Complex complex(double real) {
    return new Complex(real, 0);
  }

  protected Complex complex(double real, double imaginary) {
    return new Complex(real, imaginary);
  }
View Full Code Here

        real = realVector.getElementAsDouble(i % realVector.length());
      }
      if(imaginaryVector.length() > 0) {
        imaginary = imaginaryVector.getElementAsDouble(i % imaginaryVector.length());
      }
      result.add(new Complex(real, imaginary));
    }
    return result.build();
  }
View Full Code Here

  }
 
  @Builtin
  @DataParallel
  public static Complex Conj(Complex z){
    return new Complex(z.getReal(),-1*z.getImaginary());
  }
View Full Code Here

  @Override
  public Complex getElementAsComplex(int index) {
    if(IntVector.isNA(getElementAsRawLogical(index))) {
      return ComplexVector.NA;
    }
    return new Complex(getElementAsDouble(index), 0);
  }
View Full Code Here

      return set(size, value);
    }

    @Override
    public Builder add(Number value) {
      return add(new Complex(value.doubleValue(),0));
    }
View Full Code Here

    }

    public void ensureCapacity(int minCapacity) {
      int oldCapacity = values.length;
      if (minCapacity > oldCapacity) {
        Complex oldData[] = values;
        int newCapacity = (oldCapacity * 3)/2 + 1;
        if (newCapacity < minCapacity)
          newCapacity = minCapacity;
        // minCapacity is usually close to size, so this is a win:
        values = Arrays.copyOf(oldData, newCapacity);
View Full Code Here

TOP

Related Classes of org.apache.commons.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.