Class ComplexNumber

java.lang.Object
org.sm.smtools.math.complex.ComplexNumber

public final class ComplexNumber extends 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:
31/08/2022
Author:
Sven Maerivoet
  • Field Details

    • kZero

      public static final ComplexNumber kZero
      The constant 0 + 0i.
    • kOne

      public static final ComplexNumber kOne
      The constant 1 + 0i.
    • kTwo

      public static final ComplexNumber kTwo
      The constant 2 + 0i.
    • kThree

      public static final ComplexNumber kThree
      The constant 3 + 0i.
    • kE

      public static final ComplexNumber kE
      The constant e.
    • kI

      public static final ComplexNumber 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 component
      imaginaryComponent - the imaginary component
    • ComplexNumber

      public ComplexNumber(ComplexNumber c)
      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 component
      imaginaryComponent - 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

      public ComplexNumber negate()
      Returns the negative of this complex number.
      Returns:
      the negative of this complex number
    • cabs

      public ComplexNumber 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

      public ComplexNumber add(ComplexNumber c)
      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

      public ComplexNumber subtract(ComplexNumber c)
      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

      public ComplexNumber multiply(ComplexNumber c)
      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

      public ComplexNumber 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

      public ComplexNumber conjugate()
      Returns a reference to the conjugate of this complex number.
      Returns:
      a reference to the conjugate
    • reciprocal

      public ComplexNumber reciprocal()
      Returns a reference to the reciprocal of this complex number.
      Returns:
      a reference to the reciprocal
    • divide

      public ComplexNumber divide(ComplexNumber c)
      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

      public 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.
      Returns:
      a reference to the absolute value of the square root of this complex number
    • cbrt

      public ComplexNumber 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

      public ComplexNumber sqr()
      Returns a reference to the square of this complex number.
      Returns:
      a reference to the square of this complex number
    • cube

      public ComplexNumber cube()
      Returns a reference to the cube of this complex number.
      Returns:
      a reference to the cube of this complex number
    • pow

      public ComplexNumber pow(double n)
      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

      public ComplexNumber pow(ComplexNumber n)
      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

      public ComplexNumber 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

      public ComplexNumber 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

      public ComplexNumber logBase(ComplexNumber base)
      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

      public ComplexNumber 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

      public ComplexNumber 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

      public ComplexNumber 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

      public ComplexNumber 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

      public ComplexNumber 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

      public ComplexNumber 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

      public ComplexNumber 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

      public ComplexNumber 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

      public ComplexNumber 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

      public ComplexNumber 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

      public ComplexNumber 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

      public ComplexNumber componentMultiply(ComplexNumber z)
      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

      public ComplexNumber dotProduct(ComplexNumber z)
      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

      public ComplexNumber crossProduct(ComplexNumber z)
      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

      public String toString()
      Returns a String representation of this complex number.
      Overrides:
      toString in class Object
      Returns:
      a String representation of this complex number
    • convertPolarToComplex

      public ComplexNumber convertPolarToComplex(Double modulus, Double argument)
      Converts from polar to complex form.
      Parameters:
      modulus - the modulus of the specified polar form
      argument - the argument of the specified polar form
      Returns:
      a complex number corresponding to the specified polar form
    • compareTo

      public int compareTo(ComplexNumber c)
      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

      public boolean equals(ComplexNumber c)
      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 Object clone()
      Overrides:
      clone in class Object
    • forcePartialOrder

      public static void forcePartialOrder(ComplexNumber c1, ComplexNumber c2)
      Forces a partial order on two complex numbers c1 and c2 such that (Re1',Im1') ≤ (Re2',Im2').
      Parameters:
      c1 - the first complex number
      c2 - the second complex number