jsat.math
Class Complex
- java.lang.Object
-
- jsat.math.Complex
-
- All Implemented Interfaces:
- java.io.Serializable, java.lang.Cloneable
public class Complex extends java.lang.Object implements java.lang.Cloneable, java.io.SerializableA class for representing a complex value by a real and imaginary double pair.- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor and Description Complex(double real, double imag)Creates a new Complex number
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method and Description Complexadd(Complex c)Creates a new complex number containing the resulting addition of this and anotherstatic voidcDiv(double a, double b, double c, double d, double[] results)Performs a complex division operation.static voidcMul(double a, double b, double c, double d, double[] results)Performs a complex multiplicationComplexdivide(Complex c)Creates a new complex number containing the resulting division of this by anotherbooleanequals(java.lang.Object obj)booleanequals(java.lang.Object obj, double eps)Checks if this is approximately equal to another Complex objectdoublegetArg()Computes the Argument, also called phase, of this complex number.ComplexgetConjugate()Returns a new complex number representing the complex conjugate of this onedoublegetImag()Returns the imaginary part of this complex numberdoublegetMagnitude()doublegetReal()Returns the real part of this complex numberinthashCode()static ComplexI()Returns the complex number representing sqrt(-1)Complexmultiply(Complex c)Creates a new complex number containing the resulting multiplication between this and anothervoidmutableAdd(Complex c)Alters this complex number to contain the result of the addition of anothervoidmutableAdd(double r, double i)Alters this complex number as if an addition of another complex number was performed.voidmutableDivide(Complex c)Alters this complex number to contain the result of the division by anothervoidmutableDivide(double c, double d)Alters this complex number as if a division by another complex number was performed.voidmutableMultiply(Complex c)Alters this complex number to contain the result of the multiplication of anothervoidmutableMultiply(double c, double d)Alters this complex number as if a multiplication of another complex number was performed.voidmutableSubtract(Complex c)Alters this complex number to contain the result of the subtraction of anothervoidmutableSubtract(double r, double i)Alters this complex number as if a subtraction of another complex number was performed.voidmutateConjugate()Alters this complex number so that it represents its complex conjugate instead.voidsetImag(double imag)Sets the imaginary value part of this complex numbervoidsetReal(double r)Sets the real value part of this complex numberComplexsubtract(Complex c)Creates a new complex number containing the resulting subtracting another from this onejava.lang.StringtoString()
-
-
-
Constructor Detail
-
Complex
public Complex(double real, double imag)Creates a new Complex number- Parameters:
real- the real part of the numberimag- the imaginary part of the number
-
-
Method Detail
-
I
public static Complex I()
Returns the complex number representing sqrt(-1)- Returns:
- the complex number i
-
getReal
public double getReal()
Returns the real part of this complex number- Returns:
- the real part of this complex number
-
setReal
public void setReal(double r)
Sets the real value part of this complex number- Parameters:
r- the new real value
-
setImag
public void setImag(double imag)
Sets the imaginary value part of this complex number- Parameters:
imag- the new imaginary value
-
getImag
public double getImag()
Returns the imaginary part of this complex number- Returns:
- the imaginary part of this complex number
-
mutableAdd
public void mutableAdd(double r, double i)Alters this complex number as if an addition of another complex number was performed.- Parameters:
r- the real part of the other numberi- the imaginary part of the other number
-
mutableAdd
public void mutableAdd(Complex c)
Alters this complex number to contain the result of the addition of another- Parameters:
c- the complex value to add to this
-
add
public Complex add(Complex c)
Creates a new complex number containing the resulting addition of this and another- Parameters:
c- the number to add- Returns:
- this+c
-
mutableSubtract
public void mutableSubtract(double r, double i)Alters this complex number as if a subtraction of another complex number was performed.- Parameters:
r- the real part of the other numberi- the imaginary part of the other number
-
mutableSubtract
public void mutableSubtract(Complex c)
Alters this complex number to contain the result of the subtraction of another- Parameters:
c- the number to subtract
-
subtract
public Complex subtract(Complex c)
Creates a new complex number containing the resulting subtracting another from this one- Parameters:
c- the number to subtract- Returns:
- this-c
-
cMul
public static void cMul(double a, double b, double c, double d, double[] results)Performs a complex multiplication- Parameters:
a- the real part of the first numberb- the imaginary part of the first numberc- the real part of the second numberd- the imaginary part of the second numberresults- an array to store the real and imaginary results in. First index is the real, 2nd is the imaginary.
-
mutableMultiply
public void mutableMultiply(double c, double d)Alters this complex number as if a multiplication of another complex number was performed.- Parameters:
c- the real part of the other numberd- the imaginary part of the other number
-
mutableMultiply
public void mutableMultiply(Complex c)
Alters this complex number to contain the result of the multiplication of another- Parameters:
c- the number to multiply by
-
multiply
public Complex multiply(Complex c)
Creates a new complex number containing the resulting multiplication between this and another- Parameters:
c- the number to multiply by- Returns:
- this*c
-
cDiv
public static void cDiv(double a, double b, double c, double d, double[] results)Performs a complex division operation.
The standard complex division performs a set of operations that is suseptible to both overflow and underflow. This method is more numerically stable while still being relatively fast to execute.- Parameters:
a- the real part of the first numberb- the imaginary part of the first numberc- the real part of the second numberd- the imaginary part of the second numberresults- an array to store the real and imaginary results in. First index is the real, 2nd is the imaginary.
-
mutableDivide
public void mutableDivide(double c, double d)Alters this complex number as if a division by another complex number was performed.- Parameters:
c- the real part of the other numberd- the imaginary part of the other number
-
mutableDivide
public void mutableDivide(Complex c)
Alters this complex number to contain the result of the division by another- Parameters:
c- the number to divide by
-
divide
public Complex divide(Complex c)
Creates a new complex number containing the resulting division of this by another- Parameters:
c- the number to divide by- Returns:
- this/c
-
getMagnitude
public double getMagnitude()
- Returns:
- the magnitude of this complex number
-
getArg
public double getArg()
Computes the Argument, also called phase, of this complex number. Unless the result isDouble.NaN, which occurs only for complex zero, the result will be in the range [-pi, pi]- Returns:
- the argument of this complex number
-
mutateConjugate
public void mutateConjugate()
Alters this complex number so that it represents its complex conjugate instead.
-
getConjugate
public Complex getConjugate()
Returns a new complex number representing the complex conjugate of this one- Returns:
- the complex conjugate of this
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equalsin classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
equals
public boolean equals(java.lang.Object obj, double eps)Checks if this is approximately equal to another Complex object- Parameters:
obj- the object to compare againsteps- the maximum acceptable difference between values to be considered equal- Returns:
- true if the objects are approximately equal
-
-
DataMelt 3.0 © DataMelt by jWork.ORG