Package org.sm.smtools.math.complex
Class ComplexNumber
java.lang.Object
org.sm.smtools.math.complex.ComplexNumber
The
ComplexNumber
class provides mathematical operations on complex numbers.
The class has a partial ordering imposed, which is measured via the modulus.
Note that this class is final cannot be subclassed!
- Version:
- 31/08/2022
- Author:
- Sven Maerivoet
-
Field Summary
Modifier and TypeFieldDescriptionstatic final ComplexNumber
The constant e.static final ComplexNumber
The constant i.static final ComplexNumber
The constant 1 + 0i.static final ComplexNumber
The constant 3 + 0i.static final ComplexNumber
The constant 2 + 0i.static final ComplexNumber
The constant 0 + 0i. -
Constructor Summary
ConstructorDescriptionConstructs a complex number equal to 0 + 0i.ComplexNumber
(double realComponent) Constructs a complex number as a real number with a zero imaginary component.ComplexNumber
(double realComponent, double imaginaryComponent) Constructs a complex number with a specified value.The copy-constructor. -
Method Summary
Modifier and TypeMethodDescriptionadd
(ComplexNumber c) Add the specified complex number to this one and returns a reference to the result.double
argument()
Returns the argument (phase) of this complex number (the result lies between 0 and 2 * Math.PI).cabs()
Returns the complex absolute of this complex number.cbrt()
Calculates the cubic root of this complex number and returns a reference to the result.clone()
int
Compares this complex number to another one, via a partial ordering based on their moduli.Calculates the component-wise multiplication of this complex number and another one.Returns a reference to the conjugate of this complex number.convertPolarToComplex
(Double modulus, Double argument) Converts from polar to complex form.cos()
Takes the cosine of this complex number and returns a reference to the result.cosec()
Takes the cosecans (= 1/sin) of this complex number and returns a reference to the result.cosh()
Takes the hyperbolic cosine of this complex number and returns a reference to the result.cot()
Takes the cotangent (= cos/sin) of this complex number and returns a reference to the result.cotanh()
Takes the hyperbolic cotangent of this complex number and returns a reference to the result.Calculates the cross product of this complex number and another one.cube()
Returns a reference to the cube of this complex number.Divides this complex number by the specified one and returns a reference to the result.Calculates the dot product of this complex number and another one.boolean
Compares this complex number to another one for total equality.exp()
Takes the exponential of this complex number and returns a reference to the result.static void
Forces a partial order on two complex numbers c1 and c2 such that (Re1',Im1') ≤ (Re2',Im2').double
Returns the imaginary component of this complex number.inverse()
Returns the multiplicative inverse and returns a reference to the result.boolean
Returns whether or not this complex number is only imaginary.boolean
isReal()
Returns whether or not this complex number is only real.ln()
Takes the natural logarithm of this complex number and returns a reference to the result.log()
Takes the base 10 logarithm of this complex number and returns a reference to the result.logBase
(ComplexNumber base) Takes a custom logarithm of this complex number and returns a reference to the result.double
modulus()
Returns the modulus of this complex number.double
Returns the squared modulus of this complex number.Multiplies the specified complex number with this one and returns a reference to the result.negate()
Returns the negative of this complex number.pow
(double n) Exponentiates this complex number to a specified real power and returns a reference to the result.pow
(ComplexNumber n) Exponentiates this complex number to a specified complex power and returns a reference to the result.double
Returns the real component of this complex number.Returns a reference to the reciprocal of this complex number.sec()
Takes the secans (= 1/cos) of this complex number and returns a reference to the result.void
set
(double realComponent, double imaginaryComponent) Explicitly sets the real and imaginary components of the complex number.sin()
Takes the sine of this complex number and returns a reference to the result.sinh()
Takes the hyperbolic sine of this complex number and returns a reference to the result.sqr()
Returns a reference to the square of this complex number.sqrt()
Calculates the absolute value of the square root (i.e., the principal square root) of this complex number and returns a reference to the result.Subtracts the specified complex number from this one and returns a reference to the result.tan()
Takes the tangent (= sin/cos) of this complex number and returns a reference to the result.tanh()
Takes the hyperbolic tangent of this complex number and returns a reference to the result.toString()
Returns aString
representation of this complex number.
-
Field Details
-
kZero
The constant 0 + 0i. -
kOne
The constant 1 + 0i. -
kTwo
The constant 2 + 0i. -
kThree
The constant 3 + 0i. -
kE
The constant e. -
kI
The constant i.
-
-
Constructor Details
-
ComplexNumber
public ComplexNumber()Constructs a complex number equal to 0 + 0i. -
ComplexNumber
public ComplexNumber(double realComponent) Constructs a complex number as a real number with a zero imaginary component.- Parameters:
realComponent
- the real component
-
ComplexNumber
public ComplexNumber(double realComponent, double imaginaryComponent) Constructs a complex number with a specified value.- Parameters:
realComponent
- the real componentimaginaryComponent
- the imaginary component
-
ComplexNumber
The copy-constructor.- Parameters:
c
- the complex number to copy
-
-
Method Details
-
set
public void set(double realComponent, double imaginaryComponent) Explicitly sets the real and imaginary components of the complex number.- Parameters:
realComponent
- the real componentimaginaryComponent
- the imaginary component
-
realComponent
public double realComponent()Returns the real component of this complex number.- Returns:
- the real component of this complex number
-
imaginaryComponent
public double imaginaryComponent()Returns the imaginary component of this complex number.- Returns:
- the imaginary component of this complex number
-
isReal
public boolean isReal()Returns whether or not this complex number is only real.- Returns:
- whether or not this complex number is only real
-
isImaginary
public boolean isImaginary()Returns whether or not this complex number is only imaginary.- Returns:
- whether or not this complex number is only imaginary
-
negate
Returns the negative of this complex number.- Returns:
- the negative of this complex number
-
cabs
Returns the complex absolute of this complex number.It is defined as abs(real) + i abs(imaginary).
- Returns:
- the complex absolute of this complex number
-
add
Add the specified complex number to this one and returns a reference to the result.- Parameters:
c
- the complex number to add- Returns:
- a reference to the result
-
subtract
Subtracts the specified complex number from this one and returns a reference to the result.- Parameters:
c
- the complex number to subtract- Returns:
- a reference to the subtraction
-
multiply
Multiplies the specified complex number with this one and returns a reference to the result.- Parameters:
c
- the complex number to multiply with- Returns:
- a reference to the multiplication
-
inverse
Returns the multiplicative inverse and returns a reference to the result.- Returns:
- a reference to the multiplicative inverse
-
modulus
public double modulus()Returns the modulus of this complex number.- Returns:
- the modulus of this complex number
-
modulusSquared
public double modulusSquared()Returns the squared modulus of this complex number.- Returns:
- the squared modulus of this complex number
-
argument
public double argument()Returns the argument (phase) of this complex number (the result lies between 0 and 2 * Math.PI).- Returns:
- the argument (phase) of this complex number
-
conjugate
Returns a reference to the conjugate of this complex number.- Returns:
- a reference to the conjugate
-
reciprocal
Returns a reference to the reciprocal of this complex number.- Returns:
- a reference to the reciprocal
-
divide
Divides this complex number by the specified one and returns a reference to the result.- Parameters:
c
- the complex number to divide by- Returns:
- a reference to the division
-
sqrt
Calculates the absolute value of the square root (i.e., the principal square root) of this complex number and returns a reference to the result.- Returns:
- a reference to the absolute value of the square root of this complex number
-
cbrt
Calculates the cubic root of this complex number and returns a reference to the result.- Returns:
- a reference to the cubic root of this complex number
-
sqr
Returns a reference to the square of this complex number.- Returns:
- a reference to the square of this complex number
-
cube
Returns a reference to the cube of this complex number.- Returns:
- a reference to the cube of this complex number
-
pow
Exponentiates this complex number to a specified real power and returns a reference to the result.If the modulus is 0, then the result is 0 + 0i.
- Parameters:
n
- the real power for the exponentiation- Returns:
- a reference to this exponentiated complex number
-
pow
Exponentiates this complex number to a specified complex power and returns a reference to the result.If the modulus is 0, then the result is 0 + 0i.
- Parameters:
n
- the complex power for the exponentiation- Returns:
- a reference to this exponentiated complex number
-
ln
Takes the natural logarithm of this complex number and returns a reference to the result.- Returns:
- a reference to the natural logarithm of this complex number
-
log
Takes the base 10 logarithm of this complex number and returns a reference to the result.- Returns:
- a reference to the base 10 logarithm of this complex number
-
logBase
Takes a custom logarithm of this complex number and returns a reference to the result.- Parameters:
base
- the base of the custom logarithm- Returns:
- a reference to the custom logarithm of this complex number
-
exp
Takes the exponential of this complex number and returns a reference to the result.- Returns:
- a reference to the exponential of this complex number
-
cos
Takes the cosine of this complex number and returns a reference to the result.- Returns:
- a reference to the cosine of this complex number
-
sin
Takes the sine of this complex number and returns a reference to the result.- Returns:
- a reference to the sine of this complex number
-
tan
Takes the tangent (= sin/cos) of this complex number and returns a reference to the result.- Returns:
- a reference to the tangent of this complex number
-
cot
Takes the cotangent (= cos/sin) of this complex number and returns a reference to the result.- Returns:
- a reference to the cotangent of this complex number
-
sec
Takes the secans (= 1/cos) of this complex number and returns a reference to the result.- Returns:
- a reference to the secans of this complex number
-
cosec
Takes the cosecans (= 1/sin) of this complex number and returns a reference to the result.- Returns:
- a reference to the cosecans of this complex number
-
sinh
Takes the hyperbolic sine of this complex number and returns a reference to the result.- Returns:
- a reference to the hyperbolic sine of this complex number
-
cosh
Takes the hyperbolic cosine of this complex number and returns a reference to the result.- Returns:
- a reference to the hyperbolic cosine of this complex number
-
tanh
Takes the hyperbolic tangent of this complex number and returns a reference to the result.- Returns:
- a reference to the hyperbolic tangent of this complex number
-
cotanh
Takes the hyperbolic cotangent of this complex number and returns a reference to the result.- Returns:
- a reference to the hyperbolic cotangent of this complex number
-
componentMultiply
Calculates the component-wise multiplication of this complex number and another one.- Returns:
- a reference to the component-wise multiplication of this complex number and another one
-
dotProduct
Calculates the dot product of this complex number and another one.- Returns:
- a reference to the dot product of this complex number and another one
-
crossProduct
Calculates the cross product of this complex number and another one.- Returns:
- a reference to the cross product of this complex number and another one
-
toString
Returns aString
representation of this complex number. -
convertPolarToComplex
Converts from polar to complex form.- Parameters:
modulus
- the modulus of the specified polar formargument
- the argument of the specified polar form- Returns:
- a complex number corresponding to the specified polar form
-
compareTo
Compares this complex number to another one, via a partial ordering based on their moduli.- Parameters:
c
- the complex number to compare to- Returns:
- -1, 0, or 1 as this complex number's modulus is numerically less than, equal to, or greater than that of c
-
equals
Compares this complex number to another one for total equality.- Parameters:
c
- the complex number to compare to- Returns:
true
if both complex numbers are equal,false
otherwise
-
clone
-
forcePartialOrder
Forces a partial order on two complex numbers c1 and c2 such that (Re1',Im1') ≤ (Re2',Im2').- Parameters:
c1
- the first complex numberc2
- the second complex number
-