qcnn
Class Complex

java.lang.Object
  extended by qcnn.Complex

 class Complex
extends java.lang.Object

Allows manipulation of complex numbers. Implementation is such that a complex number is immutable; arithmetic operations may therefore be combined using any combination of composed or cascaded method invocations.


Field Summary
static boolean DEBUG_WARNINGS
          Set to true to enable warnings
static Complex I
           
protected  double im
           
static Complex ONE
           
protected  double re
           
static Complex ZERO
           
 
Constructor Summary
Complex(double d)
          Creates a new complex number with no imaginary component
Complex(double re, double im)
          Creates a new complex number
 
Method Summary
 Complex add(Complex c)
           
 Complex add(double d)
           
 double argument()
          If the modulus of the number is zero, then the argument returned will be zero.
 Complex conjugate()
           
 Complex divide(Complex c)
           
 Complex divide(double d)
           
static Complex e(Complex c)
          Returns the exponent of a complex number
 boolean equals(java.lang.Object o)
           
 double modulus()
           
 double modulusSquared()
           
 Complex multiply(Complex c)
           
 Complex multiply(double d)
           
 Complex negate()
           
static Complex polar(double r, double theta)
          Constructs a complex number from modulus and argument components
 double pow()
           
 Complex reciprocal()
           
 Complex sqrt()
           
 Complex subtract(Complex c)
           
 Complex subtract(double d)
           
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

re

protected double re

im

protected double im

DEBUG_WARNINGS

public static boolean DEBUG_WARNINGS
Set to true to enable warnings


ONE

public static final Complex ONE

ZERO

public static final Complex ZERO

I

public static final Complex I
Constructor Detail

Complex

public Complex(double re,
               double im)
Creates a new complex number

Parameters:
re - The real part of this number
im - The imaginary part of this number

Complex

public Complex(double d)
Creates a new complex number with no imaginary component

Parameters:
re - The real part of this number
Method Detail

add

public Complex add(double d)
Returns:
This number plus the specified real number

add

public Complex add(Complex c)
Returns:
This number plus the specified complex number

subtract

public Complex subtract(double d)
Returns:
This number minus the specified real number

subtract

public Complex subtract(Complex c)
Returns:
This number minus the specified complex number

multiply

public Complex multiply(double d)
Returns:
This number multiplied by the specified real number

multiply

public Complex multiply(Complex c)
Returns:
This number multiplied by the specified complex number

divide

public Complex divide(double d)
Returns:
This number divided by the specified real number

divide

public Complex divide(Complex c)
Returns:
This number divided by the specified complex number

modulus

public double modulus()
Returns:
The modulus of this complex number

argument

public double argument()
If the modulus of the number is zero, then the argument returned will be zero.

Returns:
The argument, in radians, of this complex number

negate

public Complex negate()
Returns:
The negation of this complex number

conjugate

public Complex conjugate()

reciprocal

public Complex reciprocal()
Returns:
The reciprocal of this complex number

sqrt

public Complex sqrt()
Returns:
The square root of this complex number

pow

public double pow()
Returns:
the second power of this complex number

modulusSquared

public double modulusSquared()
Returns:
The square of the modulus of this complex number

equals

public boolean equals(java.lang.Object o)
Overrides:
equals in class java.lang.Object
Parameters:
o - The complex number to compare to this one
Returns:
true if the specified complex number is equal to this one, else false
Throws:
java.lang.NullPointerException - If o is null
java.lang.ClassCastException - If o is not a complex number

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object
Returns:
A string representation of this number, of the form a+bi, where a and b are real numbers

polar

public static Complex polar(double r,
                            double theta)
Constructs a complex number from modulus and argument components

Parameters:
r - The modulus
theta - The argument
Returns:
r*exp(i*theta)

e

public static Complex e(Complex c)
Returns the exponent of a complex number

Parameters:
c - The number to be exponentiated
Returns:
exp(c);