marf.math
Class ComplexNumber

java.lang.Object
  extended by marf.math.ComplexNumber
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable

public final class ComplexNumber
extends java.lang.Object
implements java.lang.Cloneable, java.io.Serializable

Implements complex number arithmetic.

$Id: ComplexNumber.java,v 1.3 2007/12/18 03:45:42 mokhov Exp $

Since:
0.3.0.6
Version:
$Revision: 1.3 $
Author:
Serguei Mokhov
See Also:
Serialized Form

Field Summary
protected  double dImaginary
           
protected  double dReal
           
 
Constructor Summary
ComplexNumber()
           
ComplexNumber(ComplexNumber poNumber)
          Copy-constructor.
ComplexNumber(double pdReal)
           
ComplexNumber(double pdReal, double pdImaginary)
           
 
Method Summary
 double abs()
          abs(this) = |this|.
static double abs(ComplexNumber poNumber)
          Magnitude = abs(z) = |z|.
 ComplexNumber add(ComplexNumber poNumber2)
          this = this + C.
static ComplexNumber add(ComplexNumber poNumber1, ComplexNumber poNumber2)
          C3 = C1 + C2.
 double arg()
           
static double arg(ComplexNumber poNumber)
           
 ComplexNumber divide(ComplexNumber poNumber2)
          this = this / C.
static ComplexNumber divide(ComplexNumber poNumber1, ComplexNumber poNumber2)
          C3 = C1 / C2.
 boolean equals(java.lang.Object poNumber)
          Two complex numbers are equal if and only if their real parts are equal and their imaginary parts are equal.
 double getImaginary()
          Allows querying for TODO.
 double getPhaseAngle()
           
 double getRadius()
           
 double getReal()
          Allows querying for TODO.
 int hashCode()
           
 ComplexNumber multiply(ComplexNumber poNumber2)
          this = this * C.
static ComplexNumber multiply(ComplexNumber poNumber1, ComplexNumber poNumber2)
          C3 = C1 * C2.
static ComplexNumber pow(ComplexNumber poNumber, double pdPower)
          z1 = z ^ n.
 ComplexNumber pow(double pdPower)
          this = this ^ n.
 ComplexNumber set(ComplexNumber poNumber)
          this = C.
 void setImaginary(double pdImaginary)
          Allows setting TODO.
 void setPhaseAngle(double pdPhaseAngle)
          Sets real and imaginary parts given the phase angle in the polar coordinates.
 void setPolarCoordinates(double pdPhaseAngle, double pdRadius)
           
 void setReal(double pdReal)
          Allows setting TODO.
 ComplexNumber subtract(ComplexNumber poNumber2)
          this = this - C.
static ComplexNumber subtract(ComplexNumber poNumber1, ComplexNumber poNumber2)
          C3 = C1 - C2.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

dReal

protected double dReal

dImaginary

protected double dImaginary
Constructor Detail

ComplexNumber

public ComplexNumber()

ComplexNumber

public ComplexNumber(double pdReal,
                     double pdImaginary)
Parameters:
pdReal -
pdImaginary -

ComplexNumber

public ComplexNumber(double pdReal)
Parameters:
pdReal -

ComplexNumber

public ComplexNumber(ComplexNumber poNumber)
Copy-constructor.

Parameters:
poNumber - the complex number to copy
Method Detail

add

public static ComplexNumber add(ComplexNumber poNumber1,
                                ComplexNumber poNumber2)
C3 = C1 + C2.

Parameters:
poNumber1 - C1
poNumber2 - C2
Returns:
C3

add

public ComplexNumber add(ComplexNumber poNumber2)
this = this + C.

Parameters:
poNumber2 - C
Returns:
new this

subtract

public static ComplexNumber subtract(ComplexNumber poNumber1,
                                     ComplexNumber poNumber2)
C3 = C1 - C2.

Parameters:
poNumber1 - C1
poNumber2 - C2
Returns:
C3

subtract

public ComplexNumber subtract(ComplexNumber poNumber2)
this = this - C.

Parameters:
poNumber2 - C
Returns:
new this

multiply

public static ComplexNumber multiply(ComplexNumber poNumber1,
                                     ComplexNumber poNumber2)
C3 = C1 * C2.

Parameters:
poNumber1 - C1
poNumber2 - C2
Returns:
C3

multiply

public ComplexNumber multiply(ComplexNumber poNumber2)
this = this * C.

Parameters:
poNumber2 - C
Returns:
new this

divide

public static ComplexNumber divide(ComplexNumber poNumber1,
                                   ComplexNumber poNumber2)
C3 = C1 / C2.

Parameters:
poNumber1 - C1
poNumber2 - C2
Returns:
C3

divide

public ComplexNumber divide(ComplexNumber poNumber2)
this = this / C.

Parameters:
poNumber2 - C
Returns:
new this

abs

public static double abs(ComplexNumber poNumber)
Magnitude = abs(z) = |z|.

Parameters:
poNumber - z
Returns:
|z|

abs

public double abs()
abs(this) = |this|.

Returns:
new this

arg

public static double arg(ComplexNumber poNumber)
Parameters:
poNumber -
Returns:
arg(z)

arg

public double arg()
Returns:
arg(this)

pow

public static ComplexNumber pow(ComplexNumber poNumber,
                                double pdPower)
z1 = z ^ n.

Parameters:
poNumber - z
pdPower - n
Returns:
z1

pow

public ComplexNumber pow(double pdPower)
this = this ^ n.

Parameters:
pdPower - n
Returns:
this

set

public ComplexNumber set(ComplexNumber poNumber)
this = C.

Parameters:
poNumber - C
Returns:
old this

getImaginary

public double getImaginary()
Allows querying for TODO.

Returns:
returns the value dImaginary field.

setImaginary

public void setImaginary(double pdImaginary)
Allows setting TODO.

Parameters:
pdImaginary - the new value of dImaginary to set.

getReal

public double getReal()
Allows querying for TODO.

Returns:
returns the value dReal field.

setReal

public void setReal(double pdReal)
Allows setting TODO.

Parameters:
pdReal - the new value of dReal to set.

setPhaseAngle

public void setPhaseAngle(double pdPhaseAngle)
Sets real and imaginary parts given the phase angle in the polar coordinates. Radius is assumed to be "1".

Parameters:
pdPhaseAngle - the phase angle to use

setPolarCoordinates

public void setPolarCoordinates(double pdPhaseAngle,
                                double pdRadius)
Parameters:
pdPhaseAngle -
pdRadius -

getPhaseAngle

public double getPhaseAngle()
Returns:

getRadius

public double getRadius()
Returns:

equals

public boolean equals(java.lang.Object poNumber)
Two complex numbers are equal if and only if their real parts are equal and their imaginary parts are equal.

Overrides:
equals in class java.lang.Object
See Also:
Object.equals(java.lang.Object)

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object
See Also:
Object.hashCode()

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object
See Also:
Object.toString()


SourceForge Logo