ch.aplu.util
Class Complex

java.lang.Object
  extended by ch.aplu.util.Complex

public class Complex
extends java.lang.Object

This is a complex number class with the essential features needed for computations. The real and imaginary parts can be accessed directly for fast operation. (See ComplexImm for an immutable version of a complex number class.) Several of the common complex number operations are provided as static methods. New instances of Complex are returned by these methods. Code from book: Lindsey, Tolliver, Lindblad, "JavaTech, an Introduction to Scientific and Technical Computing with Java" with some minor modifications.


Field Summary
 double img
           
 double real
           
 
Constructor Summary
Complex(double r, double i)
          Constructor that initializes the values.
 
Method Summary
 void add(Complex cvalue)
          Define a complex add method.
static Complex add(Complex cvalue1, Complex cvalue2)
          Define a static add method that creates a a new Complex object with the sum.
 void divide(Complex cvalue)
          Divide this complex object by the complex argument.
static Complex divide(Complex cvalue1, Complex cvalue2)
          Define a static divide method that creates a a new Complex object with the result of cvalue1/cvalue2.
 boolean equals(java.lang.Object obj)
          Check for the equality of this object with that of the argument.
 double getImg()
          Get method for imaginary part.
 double getReal()
          Get method for real part.
 int hashCode()
          Returns a hash code value for the object.
 double modulus()
          Provide the magnitude of the complex value.
 void multiply(Complex cvalue)
          Multiply this complex object by the complex argument.
static Complex multiply(Complex cvalue1, Complex cvalue2)
          Define a static multiply method that creates a a new Complex object with the product.
 void subtract(Complex cvalue)
          Define a complex subtract method.
static Complex subtract(Complex cvalue1, Complex cvalue2)
          Define a static subtract method that creates a a new Complex object equal to cvalue1 - cvalue2.
 java.lang.String toString()
          Return a string representation of the complex value.
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

real

public double real

img

public double img
Constructor Detail

Complex

public Complex(double r,
               double i)
Constructor that initializes the values.

Method Detail

getReal

public double getReal()
Get method for real part.


getImg

public double getImg()
Get method for imaginary part.


add

public void add(Complex cvalue)
Define a complex add method.


subtract

public void subtract(Complex cvalue)
Define a complex subtract method.


add

public static Complex add(Complex cvalue1,
                          Complex cvalue2)
Define a static add method that creates a a new Complex object with the sum.


subtract

public static Complex subtract(Complex cvalue1,
                               Complex cvalue2)
Define a static subtract method that creates a a new Complex object equal to cvalue1 - cvalue2.


equals

public boolean equals(java.lang.Object obj)
Check for the equality of this object with that of the argument.

Overrides:
equals in class java.lang.Object

hashCode

public int hashCode()
Returns a hash code value for the object. In accordance with the general contract for hashCode().

Overrides:
hashCode in class java.lang.Object

modulus

public double modulus()
Provide the magnitude of the complex value.


multiply

public void multiply(Complex cvalue)
Multiply this complex object by the complex argument.


multiply

public static Complex multiply(Complex cvalue1,
                               Complex cvalue2)
Define a static multiply method that creates a a new Complex object with the product.


divide

public void divide(Complex cvalue)
Divide this complex object by the complex argument.


divide

public static Complex divide(Complex cvalue1,
                             Complex cvalue2)
Define a static divide method that creates a a new Complex object with the result of cvalue1/cvalue2.


toString

public java.lang.String toString()
Return a string representation of the complex value.

Overrides:
toString in class java.lang.Object