Example usage for org.apache.commons.math3.complex Complex getImaginary

List of usage examples for org.apache.commons.math3.complex Complex getImaginary

Introduction

In this page you can find the example usage for org.apache.commons.math3.complex Complex getImaginary.

Prototype

public double getImaginary() 

Source Link

Document

Access the imaginary part.

Usage

From source file:org.interpss.numeric.datatype.ComplexFunc.java

/**
 * Check if this obj is equal to c/*from  w ww . j av  a 2 s  .  c  o m*/
 * 
 * @param c a complex number
 * @return true/false
 */
public static boolean sameValue(final Complex a, final Complex b) {
    return ((a.getReal() == b.getReal()) && (a.getImaginary() == b.getImaginary()));
}

From source file:org.interpss.numeric.datatype.ComplexFunc.java

/**
 * Add two complex numbers togather/*from   w  w w.ja  v  a 2s. c  o m*/
 * 
 * @param a complex number
 * @param b complex number
 * @return result
 */
public static Complex add(final Complex a, final Complex b) {
    return new Complex(a.getReal() + b.getReal(), a.getImaginary() + b.getImaginary());
}

From source file:org.interpss.numeric.datatype.ComplexFunc.java

/**
 * Add three complex numbers togather//from  w w w  .  j ava2s . c o  m
 * 
 * @param a complex number
 * @param b complex number
 * @param c complex number
 * @return result
 */
public static Complex add(final Complex a, final Complex b, final Complex c) {
    return new Complex(a.getReal() + b.getReal() + c.getReal(),
            a.getImaginary() + b.getImaginary() + c.getImaginary());
}

From source file:org.interpss.numeric.datatype.ComplexFunc.java

/**
 * Subtract a - b//from  w ww  .j  a  v a 2 s  .c  o  m
 * 
 * @param a complex number
 * @param b complex number
 * @return result
 */
public static Complex sub(final Complex a, final Complex b) {
    return new Complex(a.getReal() - b.getReal(), a.getImaginary() - b.getImaginary());
}

From source file:org.interpss.numeric.datatype.ComplexFunc.java

/**
 * Division function, return d/c/*www . j av a  2s .  com*/
 * 
 * @param d double divider
 * @param c complex number
 * @return the resulting complex number
 */
public static Complex div(final double d, final Complex c) {
    final double x = d / (c.getReal() * c.getReal() + c.getImaginary() * c.getImaginary());
    return new Complex(c.getReal() * x, -c.getImaginary() * x);
}

From source file:org.interpss.numeric.datatype.ComplexFunc.java

/**
 * Division function, return d/c//from  w ww.  j ava  2s . c om
 * 
 * @param d double divider
 * @param c complex number
 * @return the resulting complex number
 */
public static Complex div(final Complex d, final Complex c) {
    Complex x = new Complex(d.getReal(), d.getImaginary());
    return x.divide(c);
}

From source file:org.interpss.numeric.datatype.ComplexFunc.java

/**
 * Division function, return c/d//from   w  w w .  j a  v  a 2s  .  co  m
 * 
 * @param c complex number
 * @param d double divider
 * @return the resulting complex number
 */
public static Complex div(final Complex c, final double d) {
    return new Complex(c.getReal() / d, c.getImaginary() / d);
}

From source file:org.interpss.numeric.datatype.ComplexFunc.java

/**
 * Multiplying function, return d*c/*  w  ww.  j  ava  2 s.  c o m*/
 * 
 * @param d double number
 * @param c complex number
 * @return the complex number
 */
public static Complex mul(final double d, final Complex c) {
    return new Complex(c.getReal() * d, c.getImaginary() * d);
}

From source file:org.interpss.numeric.datatype.ComplexFunc.java

/**
 * Multiplying function, return d*c//from  w  ww . j  a v a2 s . com
 * 
 * @param d complex number
 * @param c complex number
 * @return the complex number
 */
public static Complex mul(final Complex d, final Complex c) {
    Complex x = new Complex(d.getReal(), d.getImaginary());
    return x.multiply(c);
}

From source file:org.interpss.numeric.datatype.ComplexFunc.java

/**
 * Angle function, return the angle in rad of this obj
 * /*from  w w  w  .j av a  2 s . c om*/
 * @return the resulting angle in rad
 */
public static double arg(final Complex c) {
    // the angle in the plane in rad
    if (c.getReal() == 0.0) {
        if (c.getImaginary() > 0.0) {
            return Math.toRadians(90.0);
        } else if (c.getImaginary() < 0.0) {
            return Math.toRadians(-90.0);
        } else {
            return 0.0;
        }
    } else {
        double ang = Math.atan(c.getImaginary() / c.getReal());
        if (c.getReal() < 0.0)
            ang += Math.PI;
        return ang;
    }
}