Package com.irurueta.algebra
Class Complex
java.lang.Object
com.irurueta.algebra.Complex
- All Implemented Interfaces:
Serializable
,Cloneable
Class defining a Complex number having real and imaginary parts.
- See Also:
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionComplex()
Constructor.Complex
(double real) Creates new Complex number having provided real value and an imaginary part equal to zero.Complex
(double real, double imaginary) Creates new Complex number having provided real and imaginary parts.Creates new Complex number by copying provided value. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Adds provided complex into this instancevoid
Adds this instance with provided complex value and stores the result in provided instanceaddAndReturnNew
(Complex other) Adds this instance to provided complex and returns the result as a new instance.clone()
Makes a copy of this instance having the same real and imaginary parts.void
Changes this instance into its complex conjugate.void
Computes the complex conjugate of this instance and stores the result into provided complex instance.Computes the complex conjugate of this instance and returns the result as a new instance.void
Copies provided value into current instance.void
Divides this instance by provided complex.void
Divides this instance by provided instance and stores the result in provided instance.divideAndReturnNew
(Complex other) Divides this instance by provided instance and returns the result as a new instance.boolean
Determines whether two Complex objects are equal or not up to a certain level of tolerance in both their real and imaginary parts.boolean
Determines whether two Complex objects are equal or not.double
Returns imaginary part of complex number.double
Returns modulus of current complex number, which is equal to the length of the vector formed by the real and imaginary parts.double
getPhase()
Returns phase of current complex number, in radians.double
getReal()
Returns real part of complex number.int
hashCode()
Computes the hashcode of this instance.void
Multiplies provided complex with this instance.void
Multiplies this instance with provided instance and stores the result in provided instance.multiplyAndReturnNew
(Complex other) Multiplies provided instance with this instance and returns the result as a new instance.void
multiplyByScalar
(double scalar) Multiplies this instance by provided scalarvoid
multiplyByScalar
(double scalar, Complex result) Multiplies this instance by provided scalar value (multiplying both real and imaginary parts by provided value) and stores the result in provided complex instance.multiplyByScalarAndReturnNew
(double scalar) Multiplies this instance by provided scalar value (multiplying both real and imaginary parts by provided value) and returns the result as a new instance.void
pow
(double exponent) Computes the power of this instance by provided exponentvoid
Computes the power of this instance by provided exponent and stores the result in provided instance.powAndReturnNew
(double exponent) Computes the power of this instance by provided exponent and returns the result as a new instance.void
setImaginary
(double imaginary) Sets imaginary part of complex number.void
setModulusAndPhase
(double modulus, double phase) Sets both modulus and phase of this complex number.void
setReal
(double real) Sets real part of complex number.void
setRealAndImaginary
(double real, double imaginary) Sets both real and imaginary parts of this complex number.void
sqrt()
Computes the squared root of this instancevoid
Computes the squared root of this instance and returns the result as a new instance.Computes the squared root of this instance and returns the result as a new instance.void
Subtracts provided complex from this instance.void
Subtracts provided instance from this instance and stores the result in provided instance.subtractAndReturnNew
(Complex other) Subtracts provided instance from this instance and returns the result as a new instance
-
Field Details
-
real
private double realReal part of the complex number. -
imaginary
private double imaginaryImaginary part of the complex number.
-
-
Constructor Details
-
Complex
public Complex()Constructor. Sets both real and imaginary parts to zero. -
Complex
public Complex(double real) Creates new Complex number having provided real value and an imaginary part equal to zero.- Parameters:
real
- Real part.
-
Complex
public Complex(double real, double imaginary) Creates new Complex number having provided real and imaginary parts.- Parameters:
real
- Real part.imaginary
- Imaginary part.
-
Complex
Creates new Complex number by copying provided value.- Parameters:
initValue
- Initial value to be copied.
-
-
Method Details
-
getReal
public double getReal()Returns real part of complex number.- Returns:
- Real part.
-
setReal
public void setReal(double real) Sets real part of complex number.- Parameters:
real
- Real part.
-
getImaginary
public double getImaginary()Returns imaginary part of complex number.- Returns:
- Imaginary part.
-
setImaginary
public void setImaginary(double imaginary) Sets imaginary part of complex number.- Parameters:
imaginary
- Imaginary part.
-
setRealAndImaginary
public void setRealAndImaginary(double real, double imaginary) Sets both real and imaginary parts of this complex number.- Parameters:
real
- Real part.imaginary
- Imaginary part.
-
getModulus
public double getModulus()Returns modulus of current complex number, which is equal to the length of the vector formed by the real and imaginary parts.- Returns:
- Modulus.
-
getPhase
public double getPhase()Returns phase of current complex number, in radians. Phase is equal to the angle of the vector formed by the real and imaginary parts.- Returns:
- Phase in radians.
-
setModulusAndPhase
public void setModulusAndPhase(double modulus, double phase) Sets both modulus and phase of this complex number.- Parameters:
modulus
- Modulus to be set.phase
- Phase to be set in radians.
-
conjugate
Computes the complex conjugate of this instance and stores the result into provided complex instance. The complex conjugate is obtained by negating the sign of the imaginary part.- Parameters:
result
- Complex instance where conjugate is stored.
-
conjugateAndReturnNew
Computes the complex conjugate of this instance and returns the result as a new instance.- Returns:
- Complex conjugate.
-
conjugate
public void conjugate()Changes this instance into its complex conjugate. -
add
Adds this instance with provided complex value and stores the result in provided instance- Parameters:
other
- Complex to be added to current instance.result
- Complex instance where result is stored.
-
addAndReturnNew
Adds this instance to provided complex and returns the result as a new instance.- Parameters:
other
- Complex to be added to current instance.- Returns:
- Result of summation.
-
add
Adds provided complex into this instance- Parameters:
other
- Complex to be added to current instance.
-
subtract
Subtracts provided instance from this instance and stores the result in provided instance.- Parameters:
other
- Complex to be subtracted from this instance.result
- Complex instance where result is stored.
-
subtractAndReturnNew
Subtracts provided instance from this instance and returns the result as a new instance- Parameters:
other
- Complex to be subtracted from current instance.- Returns:
- Result of subtraction.
-
subtract
Subtracts provided complex from this instance.- Parameters:
other
- Complex to be subtracted from current instance.
-
multiply
Multiplies this instance with provided instance and stores the result in provided instance.- Parameters:
other
- Complex to be multiplied to this instanceresult
- Complex instance where result is stored.
-
multiplyAndReturnNew
Multiplies provided instance with this instance and returns the result as a new instance.- Parameters:
other
- Complex to be multiplied to current instance.- Returns:
- Result of multiplication.
-
multiply
Multiplies provided complex with this instance.- Parameters:
other
- Complex to be multiplied to this instance.
-
divide
Divides this instance by provided instance and stores the result in provided instance.- Parameters:
other
- Complex to divide this instance by.result
- Complex instance where result is stored.
-
divideAndReturnNew
Divides this instance by provided instance and returns the result as a new instance.- Parameters:
other
- Complex to divide this instance by.- Returns:
- Result of division.
-
divide
Divides this instance by provided complex.- Parameters:
other
- Complex to divide this instance by.
-
multiplyByScalar
Multiplies this instance by provided scalar value (multiplying both real and imaginary parts by provided value) and stores the result in provided complex instance.- Parameters:
scalar
- Value to multiply this instance by.result
- Complex where result of multiplication is stored.
-
multiplyByScalarAndReturnNew
Multiplies this instance by provided scalar value (multiplying both real and imaginary parts by provided value) and returns the result as a new instance.- Parameters:
scalar
- Value to multiply this instance by.- Returns:
- Result of multiplication by scalar.
-
multiplyByScalar
public void multiplyByScalar(double scalar) Multiplies this instance by provided scalar- Parameters:
scalar
- Value to multiply this instance by.
-
pow
Computes the power of this instance by provided exponent and stores the result in provided instance.- Parameters:
exponent
- Exponent to power this instance by.result
- Complex where the power is stored.
-
powAndReturnNew
Computes the power of this instance by provided exponent and returns the result as a new instance.- Parameters:
exponent
- Exponent to power this instance by.- Returns:
- Complex where the power is stored.
-
pow
public void pow(double exponent) Computes the power of this instance by provided exponent- Parameters:
exponent
- Exponent to power this instance by.
-
sqrt
Computes the squared root of this instance and returns the result as a new instance.- Parameters:
result
- Complex where squared root is stored.
-
sqrtAndReturnNew
Computes the squared root of this instance and returns the result as a new instance.- Returns:
- Squared root of this instance.
-
sqrt
public void sqrt()Computes the squared root of this instance -
equals
Determines whether two Complex objects are equal or not. Two Complex are considered to be equal if both their real and imaginary parts are equal. -
hashCode
public int hashCode()Computes the hashcode of this instance. -
equals
Determines whether two Complex objects are equal or not up to a certain level of tolerance in both their real and imaginary parts. When the difference in both their real and imaginary parts is below the tolerance level, then both instances are considered to be equal.- Parameters:
other
- Other Complex to compare.tolerance
- Margin of tolerance.- Returns:
- Returns true if both Complex instances are considered to be equal.
-
clone
Makes a copy of this instance having the same real and imaginary parts.- Overrides:
clone
in classObject
- Returns:
- a copy of this instance.
- Throws:
CloneNotSupportedException
- if clone fails.
-
copyFrom
Copies provided value into current instance.- Parameters:
value
- Value to copy from.
-