math.jwave.datatypes
Class Complex
- java.lang.Object
-
- math.jwave.datatypes.Complex
-
public class Complex extends java.lang.ObjectA class to represent a Complex Number. A Complex object is immutable once created; the add, subtract and multiply routines return newly-created Complex objects containing each requested result.
-
-
Constructor Summary
Constructors Constructor and Description Complex()Standard constructor.Complex(Complex c)Copy constructor.Complex(double r, double j)Constructor taking real and imaginary number.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method and Description Complexadd(Complex c)Add another complex number to this one and return.voidaddImag(double j)Add to imaginary number.voidaddReal(double r)Add to real number.Complexconjugate()Returns the conjugate complex number of this complex number.Complexdiv(Complex c)Divide this complex number by another one.Complexdiv(double s)Divide this complex number by a scalar.booleanequals(java.lang.Object obj)Compare this Complex number with another one.doublegetImag()Return the imaginary number.doublegetMag()Calculate the magnitude of the complex number.doublegetPhi()Calculates the angle phi of a complex number.doublegetReal()Return the real number.inthashCode()Generates a hash code for this object.Complexmul(Complex c)Multiply this complex number times another one.Complexmul(double s)Multiply this complex number times a scalar.voidmulImag(double s)multiply scalar to imaginary number.voidmulReal(double s)multiply scalar to real number.voidsetImag(double j)Set the imaginary number.voidsetReal(double r)Set the real number.voidshow()Print this complex number to console.voidshow(java.lang.String ident)Print this complex number to console with an identifier before.voidshowMag()Print magnitude to console out.voidshowPhi()Print angle to console out.Complexsub(Complex c)Subtract another complex number from this one.double[]toArr()Returns the stored values as new double array: [ real, imag ].java.lang.StringtoString()Display the current Complex as a String, for usage in println( ) and elsewhere.
-
-
-
Constructor Detail
-
Complex
public Complex()
Standard constructor.
-
Complex
public Complex(Complex c)
Copy constructor.- Parameters:
c- complex number
-
Complex
public Complex(double r, double j)Constructor taking real and imaginary number.- Parameters:
r- real numberj- imaginary number
-
-
Method Detail
-
toString
public java.lang.String toString()
Display the current Complex as a String, for usage in println( ) and elsewhere.- Overrides:
toStringin classjava.lang.Object
-
getReal
public double getReal()
Return the real number.- Returns:
- real number of this complex number
-
getImag
public double getImag()
Return the imaginary number.- Returns:
- imaginary number of this complex number
-
setReal
public void setReal(double r)
Set the real number.- Parameters:
r- the real number
-
setImag
public void setImag(double j)
Set the imaginary number.- Parameters:
j- the imaginary number
-
addReal
public void addReal(double r)
Add to real number.- Parameters:
r- the real number
-
addImag
public void addImag(double j)
Add to imaginary number.- Parameters:
j- the imaginary number
-
mulReal
public void mulReal(double s)
multiply scalar to real number.- Parameters:
s- scalar
-
mulImag
public void mulImag(double s)
multiply scalar to imaginary number.- Parameters:
s- scalar
-
getMag
public double getMag()
Calculate the magnitude of the complex number.- Returns:
- magnitude of this complex number
-
getPhi
public double getPhi()
Calculates the angle phi of a complex number.- Returns:
- angle of this complex number
-
toArr
public double[] toArr()
Returns the stored values as new double array: [ real, imag ].- Returns:
- returns stored values as array [ real, imag ]
-
conjugate
public Complex conjugate()
Returns the conjugate complex number of this complex number.- Returns:
- new object of Complex keeping the result
-
add
public Complex add(Complex c)
Add another complex number to this one and return.- Parameters:
c- complex number- Returns:
- new object of Complex keeping the result
-
sub
public Complex sub(Complex c)
Subtract another complex number from this one.- Parameters:
c- complex number- Returns:
- new object of Complex keeping the result
-
mul
public Complex mul(Complex c)
Multiply this complex number times another one.- Parameters:
c- complex number- Returns:
- new object of Complex keeping the result
-
mul
public Complex mul(double s)
Multiply this complex number times a scalar.- Parameters:
s- scalar- Returns:
- new object of Complex keeping the result
-
div
public Complex div(Complex c)
Divide this complex number by another one.- Parameters:
c- complex number- Returns:
- new object of Complex keeping the result
-
div
public Complex div(double s)
Divide this complex number by a scalar.- Parameters:
s- scalar- Returns:
- new object of Complex keeping the result
-
hashCode
public int hashCode()
Generates a hash code for this object.- Overrides:
hashCodein classjava.lang.Object- See Also:
Object.hashCode()
-
equals
public boolean equals(java.lang.Object obj)
Compare this Complex number with another one.- Overrides:
equalsin classjava.lang.Object- See Also:
Object.equals(java.lang.Object)
-
show
public void show()
Print this complex number to console.
-
show
public void show(java.lang.String ident)
Print this complex number to console with an identifier before.- Parameters:
ident- string to label this complex number
-
showMag
public void showMag()
Print magnitude to console out.
-
showPhi
public void showPhi()
Print angle to console out.
-
-
DMelt 3.0 © DataMelt by jWork.ORG