List of usage examples for org.apache.commons.math.complex Complex getImaginary
public double getImaginary()
From source file:com.discursive.jccook.math.ComplexNumbers.java
public static void main(String[] args) { Complex a = new Complex(2, 3); Complex b = new Complex(4, 5); Complex c = new Complex(0.3, 2); Complex e = new Complex(4, 4); Complex sum = a.add(b);// w w w . j av a2 s . co m Complex d = c.divide(sum); Complex f = e.multiply(d.conjugate()); System.out.println("D is: " + ComplexFormat.formatComplex(d)); System.out.println("F is: " + ComplexFormat.formatComplex(f)); double realF = f.getReal(); double imD = d.getImaginary(); double answer = realF / imD; System.out.println("Answer: " + NumberFormat.getInstance().format(answer)); }
From source file:geogebra.common.geogebra3D.kernel3D.geos.Geo3DVec.java
final public static void complexMultiply(GeoVecInterface a, GeoVecInterface b, GeoVec2D c) { if (!Kernel.isZero(a.getZ()) || !Kernel.isZero(b.getZ())) { c.setX(Double.NaN);/* w w w .j a va 2 s .co m*/ c.setY(Double.NaN); c.setMode(Kernel.COORD_COMPLEX); return; } Complex out = new Complex(a.getX(), a.getY()); out = out.multiply(new Complex(b.getX(), b.getY())); c.setX(out.getReal()); c.setY(out.getImaginary()); c.setMode(Kernel.COORD_COMPLEX); }
From source file:geogebra.kernel.GeoVec2D.java
/** c = a ^ b Michael Borcherds 2009-03-10 */ final public static void complexPower(GeoVec2D a, NumberValue b, GeoVec2D c) { Complex out = new Complex(a.x, a.y); out = out.pow(new Complex(b.getDouble(), 0)); c.x = out.getReal();//from w w w. j ava 2 s. com c.y = out.getImaginary(); c.setMode(Kernel.COORD_COMPLEX); }
From source file:geogebra.kernel.GeoVec2D.java
/** c = a / b Michael Borcherds 2007-12-09 * //from ww w.jav a2 s.co m * */ final public static void complexDivide(GeoVec2D a, GeoVec2D b, GeoVec2D c) { // NB temporary variables *crucial*: a and c can be the same variable //double x1=a.x,y1=a.y,x2=b.x,y2=b.y; // complex division //c.x = (x1 * x2 + y1 * y2)/(x2 * x2 + y2 * b.y); //c.y = (y1 * x2 - x1 * y2)/(x2 * x2 + y2 * b.y); Complex out = new Complex(a.x, a.y); out = out.divide(new Complex(b.x, b.y)); c.x = out.getReal(); c.y = out.getImaginary(); c.setMode(Kernel.COORD_COMPLEX); }
From source file:geogebra.kernel.GeoVec2D.java
/** c = a * b Michael Borcherds 2007-12-09 */ final public static void complexMultiply(GeoVec2D a, GeoVec2D b, GeoVec2D c) { // NB temporary variables *crucial*: a and c can be the same variable //double x1=a.x,y1=a.y,x2=b.x,y2=b.y; // do multiply //c.x = (x1 * x2 - y1 * y2); //c.y = (y2 * x1 + x2 * y1); Complex out = new Complex(a.x, a.y); out = out.multiply(new Complex(b.x, b.y)); c.x = out.getReal();// w w w .j a va 2 s . com c.y = out.getImaginary(); c.setMode(Kernel.COORD_COMPLEX); }
From source file:geogebra.kernel.GeoVec2D.java
/** c = a / b Michael Borcherds 2008-08-12 * // ww w . j a v a 2 s. c o m * */ final public static void complexDivide(NumberValue a, GeoVec2D b, GeoVec2D c) { // NB temporary variables *crucial*: a and c can be the same variable //double x1=a.getDouble(), x2 = b.x, y2 = b.y; // complex division //c.x = (x1 * x2 )/(x2 * x2 + y2 * b.y); //c.y = ( - x1 * y2)/(x2 * x2 + y2 * b.y); Complex out = new Complex(a.getDouble(), 0); out = out.divide(new Complex(b.x, b.y)); c.x = out.getReal(); c.y = out.getImaginary(); c.setMode(Kernel.COORD_COMPLEX); }
From source file:geogebra.kernel.GeoVec2D.java
/** c = a * b Michael Borcherds 2007-12-09 */ final public static void complexMultiply(GeoVec2D a, NumberValue b, GeoVec2D c) { // NB temporary variables *crucial*: a and c can be the same variable //double x1=a.x,y1=a.y,x2=b.getDouble(); // do multiply //c.x = (x1 * x2); //c.y = (x2 * y1); Complex out = new Complex(a.x, a.y); out = out.multiply(new Complex(b.getDouble(), 0)); c.x = out.getReal();/*w ww . j a va2s . c o m*/ c.y = out.getImaginary(); c.setMode(Kernel.COORD_COMPLEX); }
From source file:com.opengamma.analytics.math.rootfinding.LaguerrePolynomialRealRootFinder.java
/** * {@inheritDoc}//from w ww . ja v a 2 s. co m * @throws MathException If there are no real roots; if the Commons method could not evaluate the function; if the Commons method could not converge. */ @Override public Double[] getRoots(final RealPolynomialFunction1D function) { ArgumentChecker.notNull(function, "function"); try { final Complex[] roots = ROOT_FINDER.solveAll(function.getCoefficients(), 0); final List<Double> realRoots = new ArrayList<>(); for (final Complex c : roots) { if (CompareUtils.closeEquals(c.getImaginary(), 0, EPS)) { realRoots.add(c.getReal()); } } if (realRoots.isEmpty()) { throw new MathException("Could not find any real roots"); } return realRoots.toArray(EMPTY_ARRAY); } catch (final FunctionEvaluationException e) { throw new MathException(e); } catch (final org.apache.commons.math.ConvergenceException e) { throw new MathException(e); } }
From source file:geogebra.common.kernel.EquationSolver.java
/** * Returns a comparator for Complex objects. (sorts on real part coordinate) * If equal does return zero (deletes duplicates!) * // www. j av a2 s . co m * @return comparator for complex numbers */ public static Comparator<Complex> getComparatorReal() { if (comparatorReal == null) { comparatorReal = new Comparator<Complex>() { public int compare(Complex itemA, Complex itemB) { double compReal = itemA.getReal() - itemB.getReal(); if (Kernel.isZero(compReal)) { double compImaginary = itemA.getImaginary() - itemB.getImaginary(); // if real parts equal, sort on imaginary if (!Kernel.isZero(compImaginary)) return compImaginary < 0 ? -1 : +1; // return 0 -> remove duplicates! return 0; } return compReal < 0 ? -1 : +1; } }; } return comparatorReal; }
From source file:geogebra.kernel.EquationSolver.java
/** * Returns a comparator for Complex objects. * (sorts on real part coordinate)//from w w w.j av a 2 s .c om * If equal does return zero (deletes duplicates!) */ public static Comparator<Complex> getComparatorReal() { if (comparatorReal == null) { comparatorReal = new Comparator<Complex>() { public int compare(Complex itemA, Complex itemB) { double compReal = itemA.getReal() - itemB.getReal(); if (Kernel.isZero(compReal)) { double compImaginary = itemA.getImaginary() - itemB.getImaginary(); // if real parts equal, sort on imaginary if (!Kernel.isZero(compImaginary)) return compImaginary < 0 ? -1 : +1; // return 0 -> remove duplicates! return 0; } else { return compReal < 0 ? -1 : +1; } } }; } return comparatorReal; }