Class Complex
java.lang.Object
|
+--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.
|
Constructor Summary |
Complex(double d)
Creates a new complex number with no imaginary component |
Complex(double re,
double im)
Creates a new complex number |
| Methods inherited from class java.lang.Object |
,
clone,
finalize,
getClass,
hashCode,
notify,
notifyAll,
registerNatives,
wait,
wait,
wait |
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
Complex
public Complex(double re,
double im)
- Creates a new complex number
- Parameters:
re - The real part of this numberim - 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
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
reciprocal
public Complex reciprocal()
- Returns:
- The reciprocal of this complex number
sqrt
public Complex sqrt()
- Returns:
- The square root 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:
- NullPointerException - If
o is null- 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 modulustheta - 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);