Package smile.math

Class Complex

java.lang.Object
smile.math.Complex
All Implemented Interfaces:
Serializable

public class Complex extends Object implements Serializable
Complex number. The object is immutable so once you create and initialize a Complex object, you cannot modify it.
See Also:
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static class 
    Packed array of complex numbers for better memory efficiency.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    final double
    The imaginary part.
    final double
    The real part.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Complex(double real, double imag)
    Constructor.
  • Method Summary

    Modifier and Type
    Method
    Description
    double
    abs()
    Returns the abs/modulus/magnitude.
    Returns this + b.
    Returns the conjugate.
    cos()
    Returns the complex cosine.
    Returns a / b.
    boolean
     
    exp()
    Returns the complex exponential.
    int
     
    Returns this * b.
    static Complex
    of(double real)
    Returns a Complex instance representing the specified value.
    static Complex
    of(double real, double imag)
    Returns a Complex instance representing the specified value.
    double
    Returns the angle/phase/argument between -pi and pi.
    Returns the reciprocal.
    scale(double b)
    Scalar multiplication.
    sin()
    Returns the complex sine.
    Returns this - b.
    tan()
    Returns the complex tangent.
     

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Field Details

    • re

      public final double re
      The real part.
    • im

      public final double im
      The imaginary part.
  • Constructor Details

    • Complex

      public Complex(double real, double imag)
      Constructor.
      Parameters:
      real - the real part.
      imag - the imaginary part.
  • Method Details

    • of

      public static Complex of(double real)
      Returns a Complex instance representing the specified value.
      Parameters:
      real - the real part.
      Returns:
      the complex object.
    • of

      public static Complex of(double real, double imag)
      Returns a Complex instance representing the specified value.
      Parameters:
      real - the real part.
      imag - the imaginary part.
      Returns:
      the complex object.
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • add

      public Complex add(Complex b)
      Returns this + b.
      Parameters:
      b - the operand.
      Returns:
      the result.
    • sub

      public Complex sub(Complex b)
      Returns this - b.
      Parameters:
      b - the operand.
      Returns:
      the result.
    • mul

      public Complex mul(Complex b)
      Returns this * b.
      Parameters:
      b - the operand.
      Returns:
      the result.
    • scale

      public Complex scale(double b)
      Scalar multiplication.
      Parameters:
      b - the operand.
      Returns:
      the result.
    • div

      public Complex div(Complex b)
      Returns a / b.
      Parameters:
      b - the operand.
      Returns:
      the result.
    • abs

      public double abs()
      Returns the abs/modulus/magnitude.
      Returns:
      the modulus.
    • phase

      public double phase()
      Returns the angle/phase/argument between -pi and pi.
      Returns:
      the phase between -pi and pi.
    • conjugate

      public Complex conjugate()
      Returns the conjugate.
      Returns:
      the conjugate.
    • reciprocal

      public Complex reciprocal()
      Returns the reciprocal.
      Returns:
      the reciprocal.
    • exp

      public Complex exp()
      Returns the complex exponential.
      Returns:
      the complex exponential.
    • sin

      public Complex sin()
      Returns the complex sine.
      Returns:
      the complex sine.
    • cos

      public Complex cos()
      Returns the complex cosine.
      Returns:
      the complex cosine.
    • tan

      public Complex tan()
      Returns the complex tangent.
      Returns:
      the complex tangent.