Package org.sm.smtools.math.complex
Class ComplexNumber
java.lang.Object
org.sm.smtools.math.complex.ComplexNumber
public final class ComplexNumber
extends java.lang.Object
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:
- 21/09/2016
- Author:
- Sven Maerivoet
-
Field Summary
Fields Modifier and Type Field Description static ComplexNumber
kE
The constant e.static ComplexNumber
kI
The constant i.static ComplexNumber
kOne
The constant 1 + 0i.static ComplexNumber
kThree
The constant 3 + 0i.static ComplexNumber
kTwo
The constant 2 + 0i.static ComplexNumber
kZero
The constant 0 + 0i. -
Constructor Summary
Constructors Constructor Description ComplexNumber()
Constructs 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.ComplexNumber(ComplexNumber c)
The copy-constructor. -
Method Summary
Modifier and Type Method Description ComplexNumber
add(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).ComplexNumber
cabs()
Returns the complex absolute of this complex number.ComplexNumber
cbrt()
Calculates the cubic root of this complex number and returns a reference to the result.java.lang.Object
clone()
int
compareTo(ComplexNumber c)
Compares this complex number to another one, via a partial ordering based on their moduli.ComplexNumber
conjugate()
Returns a reference to the conjugate of this complex number.ComplexNumber
convertPolarToComplex(java.lang.Double modulus, java.lang.Double argument)
Converts from polar to complex form.ComplexNumber
cos()
Takes the cosine of this complex number and returns a reference to the result.ComplexNumber
cosec()
Takes the cosecans (= 1/sin) of this complex number and returns a reference to the result.ComplexNumber
cosh()
Takes the hyperbolic cosine of this complex number and returns a reference to the result.ComplexNumber
cot()
Takes the cotangent (= cos/sin) of this complex number and returns a reference to the result.ComplexNumber
cotanh()
Takes the hyperbolic cotangent of this complex number and returns a reference to the result.ComplexNumber
cube()
Returns a reference to the cube of this complex number.ComplexNumber
divide(ComplexNumber c)
Divides this complex number by the specified one and returns a reference to the result.boolean
equals(ComplexNumber c)
Compares this complex number to another one for total equality.ComplexNumber
exp()
Takes the exponential of this complex number and returns a reference to the result.static void
forcePartialOrder(ComplexNumber c1, ComplexNumber c2)
Forces a partial order on two complex numbers c1 and c2 such that (Re1',Im1') ≤ (Re2',Im2').double
imaginaryComponent()
Returns the imaginary component of this complex number.ComplexNumber
inverse()
Returns the multiplicative inverse and returns a reference to the result.boolean
isImaginary()
Returns whether or not this complex number is only imaginary.boolean
isReal()
Returns whether or not this complex number is only real.ComplexNumber
ln()
Takes the natural logarithm of this complex number and returns a reference to the result.ComplexNumber
log()
Takes the base 10 logarithm of this complex number and returns a reference to the result.ComplexNumber
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
modulusSquared()
Returns the squared modulus of this complex number.ComplexNumber
multiply(ComplexNumber c)
Multiplies the specified complex number with this one and returns a reference to the result.ComplexNumber
negate()
Returns the negative of this complex number.ComplexNumber
pow(double n)
Exponentiates this complex number to a specified real power and returns a reference to the result.ComplexNumber
pow(ComplexNumber n)
Exponentiates this complex number to a specified complex power and returns a reference to the result.double
realComponent()
Returns the real component of this complex number.ComplexNumber
reciprocal()
Returns a reference to the reciprocal of this complex number.ComplexNumber
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.ComplexNumber
sin()
Takes the sine of this complex number and returns a reference to the result.ComplexNumber
sinh()
Takes the hyperbolic sine of this complex number and returns a reference to the result.ComplexNumber
sqr()
Returns a reference to the square of this complex number.ComplexNumber
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.ComplexNumber
subtract(ComplexNumber c)
Subtracts the specified complex number from this one and returns a reference to the result.ComplexNumber
tan()
Takes the tangent (= sin/cos) of this complex number and returns a reference to the result.ComplexNumber
tanh()
Takes the hyperbolic tangent of this complex number and returns a reference to the result.java.lang.String
toString()
Returns aString
representation of this complex number.Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
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
-
toString
public java.lang.String toString()Returns aString
representation of this complex number.- Overrides:
toString
in classjava.lang.Object
- Returns:
- a
String
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
public java.lang.Object clone()- Overrides:
clone
in classjava.lang.Object
-
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
-