number
Class Complex

java.lang.Object
  extended by number.Complex

public final class Complex
extends Object

This class stores a complex number, and allows the user to do arithmetic with these numbers. Note that our complex numbers are immutable. That is, once they are constructed, they will not change. In particular, all our algebraic operations create a new complex number rather than updating the current one.


Constructor Summary
Complex(double real_part)
          Construct a real number.
Complex(double real_part, double imaginary_part)
          Construct a point from real and imaginary parts.
 
Method Summary
 double abs()
          Return the absolute value.
 double absSquared()
          Return the square of the absolute value.
 Complex add(Complex z)
          Add a complex number to this one.
 Complex conj()
          Return the complex conjugate
 Complex div(Complex z)
          Compute the quotient of two complex numbers.
 Complex div(double q)
          Divide this complex number by a real number.
 boolean equals(Object obj)
          Return true if the object is a complex number which is equal to this complex number.
 Complex exp()
          Return the complex exponential of this complex number.
 int hashCode()
           
 double im()
          Return the imaginary part.
 Complex inv()
          Return the multiplicative inverse.
 Complex minus(Complex z)
          Subtract a complex number from this one.
 Complex mult(Complex z)
          Compute the product of two complex numbers
 Complex neg()
          Negate this complex number.
 double re()
          Return the real part.
 String toString()
          Returns this point as a string.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Complex

public Complex(double real_part,
               double imaginary_part)
Construct a point from real and imaginary parts.


Complex

public Complex(double real_part)
Construct a real number.

Method Detail

re

public double re()
Return the real part.


im

public double im()
Return the imaginary part.


conj

public Complex conj()
Return the complex conjugate


absSquared

public double absSquared()
Return the square of the absolute value.


abs

public double abs()
Return the absolute value.


add

public Complex add(Complex z)
Add a complex number to this one.

Parameters:
z - The complex number to be added.
Returns:
A new complex number which is the sum.

minus

public Complex minus(Complex z)
Subtract a complex number from this one.

Parameters:
z - The complex number to be subtracted.
Returns:
A new complex number which is the sum.

neg

public Complex neg()
Negate this complex number.

Returns:
The negation.

mult

public Complex mult(Complex z)
Compute the product of two complex numbers

Parameters:
z - The complex number to be multiplied.
Returns:
A new complex number which is the product.

div

public Complex div(double q)
Divide this complex number by a real number.

Parameters:
q - The number to divide by.
Returns:
A new complex number representing the quotient.

inv

public Complex inv()
Return the multiplicative inverse.


div

public Complex div(Complex z)
Compute the quotient of two complex numbers.

Parameters:
z - The complex number to divide this one by.
Returns:
A new complex number which is the quotient.

exp

public Complex exp()
Return the complex exponential of this complex number.


toString

public String toString()
Returns this point as a string. The main purpose of this function is for printing the string out, so we return a string in a (fairly) human readable format.

Overrides:
toString in class Object

equals

public boolean equals(Object obj)
Return true if the object is a complex number which is equal to this complex number.

Overrides:
equals in class Object

hashCode

public int hashCode()
Overrides:
hashCode in class Object


Java Tutorial for Mathematics Students