Package ptolemy.math

Class Complex


  • public class Complex
    extends java.lang.Object
    This class provides a complex data type and a library of functions that operate on and return complex numbers. An instance of the class is immutable, meaning that its value is set in the constructor and cannot then be modified. This is similar to the Java built-in classes like Double, Integer, etc.

    Although this code is written from scratch, I looked at several designs and borrowed elements from each of them:

    • The ComplexSubset class in Ptolemy 0.x, written by Joe Buck, which borrowed design elements from the cfront and libg++ Complex classes.
    • Version 1.0 of the Complex class by Alma services, dated Fri 29-Aug-97, written by Sandy Anderson and Priyantha Jayanetti, and obtained from the Netlib Repository.
    • The Complex class in JNL, a Java Numerical Library, dated 1997, by Visual Numerics, Inc. This was used for interface design only, to compare the choice of method names and method templates.
    • Matlab, which was used to validate the results in the test suite, and influenced some of the method name choices.
    Since:
    Ptolemy II 0.2
    Version:
    $Id$
    Author:
    Edward A. Lee, Jeff Tsay, Steve Neuendorffer, Adam Cataldo
    Pt.AcceptedRating:
    Red (cxh)
    Pt.ProposedRating:
    Yellow (eal)
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static double EPSILON
      A small number ( = 1.0e-9).
      static Complex I
      A Complex number representing i.
      double imag
      The imaginary part.
      static Complex NEGATIVE_INFINITY
      A Complex number representing negative infinity, by which we mean that both the real and imaginary parts are equal to Double.NEGATIVE_INFINITY.
      static Complex ONE
      A Complex number representing one.
      static Complex POSITIVE_INFINITY
      A Complex number representing positive infinity, by which we mean that both the real and imaginary parts are equal to Double.POSITIVE_INFINITY.
      double real
      The real part.
      static Complex ZERO
      A Complex number representing zero.
    • Constructor Summary

      Constructors 
      Constructor Description
      Complex()
      Deprecated.
      Use Complex.ZERO instead.
      Complex​(double real)
      Construct a Complex with a zero imaginary part.
      Complex​(double real, double imag)
      Construct a Complex with the specified real and imaginary parts.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      static double abs​(Complex x)
      Return the magnitude or absolute value of the specified complex number.
      Complex acos()
      Return the principal arc cosine of this complex number.
      static Complex acos​(Complex z)
      Return the principal arc cosine of the specified complex number.
      Complex acosh()
      Return the principal hyperbolic arc cosine of this complex number.
      static Complex acosh​(Complex z)
      Return the principal hyperbolic arc cosine of the given complex number.
      Complex add​(Complex z)
      Return the sum of this complex number and the argument z.
      double angle()
      Return the angle or argument of this complex number.
      static double angle​(Complex z)
      Return the angle or argument of this complex number.
      Complex asin()
      Return the principal arc sine of this complex number.
      static Complex asin​(Complex z)
      Return the principal arc sine of the given complex number.
      Complex asinh()
      Return the principal hyperbolic arc sine of this complex number.
      static Complex asinh​(Complex z)
      Return the principal hyperbolic arc sine of the given complex number.
      Complex atan()
      Return the principal arc tangent of this complex number.
      static Complex atan​(Complex z)
      Return the principal arc tangent of the given complex number.
      Complex atanh()
      Return the principal hyperbolic arc tangent of this complex number.
      static Complex atanh​(Complex z)
      Return the principal hyperbolic arc tangent of the given complex number.
      Complex conjugate()
      Return the complex conjugate of this complex number.
      static Complex conjugate​(double z)
      Return the complex conjugate of the specified real number, which is just the real number itself.
      static Complex conjugate​(Complex z)
      Return the complex conjugate of the specified complex number.
      Complex cos()
      Return the cosine of this complex number.
      static Complex cos​(Complex z)
      Return the cosine of the given complex number.
      Complex cosh()
      Return the hyperbolic cosine of this complex number.
      static Complex cosh​(Complex z)
      Return the hyperbolic cosine of the given complex number.
      Complex cot()
      Return the cotangent of this complex number.
      static Complex cot​(Complex z)
      Return the cotangent of the given complex number.
      Complex csc()
      Return the cosecant of this complex number.
      static Complex csc​(Complex z)
      Return the cosecant of the given complex number.
      Complex divide​(Complex divisor)
      Divide this complex number by the argument, and return the result in a new Complex object.
      boolean equals​(java.lang.Object z)
      Return true if the real and imaginary parts of this complex number are equal to those of the argument.
      Complex exp()
      Return the exponential of this complex number, or ez, where z is this complex number.
      static Complex exp​(Complex z)
      Return the exponential of the specified complex number, or ez, where z is the argument.
      int hashCode()
      Return a hash code value for this Complex.
      static double imag​(double z)
      Return the imaginary part of the specified real number, which is 0.0.
      static double imag​(Complex z)
      Return the imaginary part of the specified complex number.
      boolean isCloseTo​(Complex z)
      Return true if the distance between this complex number and the argument is less than or equal to EPSILON.
      boolean isCloseTo​(Complex z, double distance)
      Return true if the distance between this complex number and the first argument is less than or equal to the second argument.
      boolean isInfinite()
      Return true if either the real or imaginary part is infinite.
      static boolean isInfinite​(Complex z)
      Return true if either the real or imaginary part of the given complex number is infinite.
      boolean isNaN()
      Return true if either the real or imaginary part is NaN.
      static boolean isNaN​(Complex z)
      Return true if either the real or imaginary part of the given Complex number is NaN.
      Complex log()
      Return the natural logarithm of this complex number.
      static Complex log​(Complex z)
      Return the natural logarithm of the specified complex number.
      double magnitude()
      Return the magnitude or absolute value of this complex number.
      static double magnitude​(Complex z)
      Return the magnitude or absolute value of the given complex number.
      double magnitudeSquared()
      Return the square of the magnitude of this complex number.
      static double magnitudeSquared​(Complex z)
      Return the square of the magnitude of this complex number.
      Complex multiply​(Complex w)
      Return a new complex number that is formed by multiplying this complex number by the specified complex number.
      Complex negate()
      Negate this complex number.
      static Complex polarToComplex​(double magnitude, double angle)
      Return a new complex number with the specified magnitude and angle.
      Complex pow​(double y)
      Return a new complex number with value z y where z is this complex number and y is the argument, a double.
      static Complex pow​(double z, Complex y)
      Return a new complex number with value z y where z is the first argument and y is the second argument.
      Complex pow​(Complex y)
      Return zy where z is this complex number and y is the argument, a Complex.
      static Complex pow​(Complex z, double y)
      Return a new complex number with value z y where z is the first argument and y is the second argument.
      static Complex pow​(Complex z, Complex y)
      Return a new complex number with value z y where z is the first argument and y is the second argument.
      static double real​(double z)
      Return the real part of the specified real number, which is the real number itself.
      static double real​(Complex z)
      Return the real part of the specified complex number.
      Complex reciprocal()
      Return the reciprocal of this complex number.
      static Complex reciprocal​(Complex z)
      Return the reciprocal of this complex number.
      Complex[] roots​(int n)
      Return the nth roots of this complex number in an array.
      static Complex[] roots​(Complex z, int n)
      Return the nth roots of the given complex number in an array.
      Complex scale​(double scalar)
      Return a new complex number with value equal to the product of this complex number and the real argument.
      Complex sec()
      Return a new complex number with value equal to the secant of this complex number.
      static Complex sec​(Complex z)
      Return a new complex number with value equal to the secant of the given complex number.
      Complex sin()
      Return a new complex number with value equal to the sine of this complex number.
      static Complex sin​(Complex z)
      Return a new complex number with value equal to the sine of the given complex number.
      Complex sinh()
      Return a new complex number with value equal to the hyperbolic sine of this complex number.
      static Complex sinh​(Complex z)
      Return a new complex number with value equal to the hyperbolic sine of this complex number.
      Complex sqrt()
      Return a new complex number with its value equal to the the square root of this complex number.
      static Complex sqrt​(Complex z)
      Return a new complex number with its value equal to the the square root of the specified complex number.
      Complex subtract​(Complex w)
      Return a new complex number formed by subtracting the specified complex number from this complex number.
      Complex tan()
      Return a new complex number with value equal to the tangent of this complex number.
      static Complex tan​(Complex z)
      Return a new complex number with value equal to the tangent of the given complex number.
      Complex tanh()
      Return a new complex number with value equal to the hyperbolic tangent of this complex number.
      static Complex tanh​(Complex z)
      Return a new complex number with value equal to the hyperbolic tangent of the given complex number.
      java.lang.String toString()
      Return a string representation of this Complex.
      static java.lang.String toString​(Complex value)
      Return a string representation of the given Complex.
      • Methods inherited from class java.lang.Object

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

      • real

        public final double real
        The real part. This is a "blank final," which means that it can only be set in the constructor.
      • imag

        public final double imag
        The imaginary part. This is a "blank final," which means that it can only be set in the constructor.
      • EPSILON

        public static double EPSILON
        A small number ( = 1.0e-9). This number is used by algorithms to detect whether a double is close to zero. This value is public so that it can be changed on platforms with different precisions. This variable is not final so that users may set it as necessary.
      • NEGATIVE_INFINITY

        public static final Complex NEGATIVE_INFINITY
        A Complex number representing negative infinity, by which we mean that both the real and imaginary parts are equal to Double.NEGATIVE_INFINITY.
      • POSITIVE_INFINITY

        public static final Complex POSITIVE_INFINITY
        A Complex number representing positive infinity, by which we mean that both the real and imaginary parts are equal to Double.POSITIVE_INFINITY.
      • ZERO

        public static final Complex ZERO
        A Complex number representing zero. Reference this to save memory usage and construction overhead.
      • ONE

        public static final Complex ONE
        A Complex number representing one. Reference this to save memory usage and construction overhead.
      • I

        public static final Complex I
        A Complex number representing i. Reference this to save memory usage and construction overhead.
    • Constructor Detail

      • Complex

        @Deprecated
        public Complex()
        Deprecated.
        Use Complex.ZERO instead.
        Construct a Complex equal to zero.
      • Complex

        public Complex​(double real)
        Construct a Complex with a zero imaginary part.
        Parameters:
        real - The real part.
      • Complex

        public Complex​(double real,
                       double imag)
        Construct a Complex with the specified real and imaginary parts.
        Parameters:
        real - The real part.
        imag - The imaginary part.
    • Method Detail

      • abs

        public static double abs​(Complex x)
        Return the magnitude or absolute value of the specified complex number.
        Parameters:
        x - The specified number.
        Returns:
        A non-negative number that is the absolute value of this complex number.
      • acos

        public final Complex acos()
        Return the principal arc cosine of this complex number. This is defined by:
           acos(z) = -i * log(z + i*sqrt(1 - z*z))
          
        where z is this complex number.
        Returns:
        A new complex number with value equal to the arc cosine of the given complex number.
      • acos

        public static Complex acos​(Complex z)
        Return the principal arc cosine of the specified complex number. This is defined by:
           acos(z) = -i * log(z + i*sqrt(1 - z*z))
          
        where z is this complex number.
        Parameters:
        z - A complex number.
        Returns:
        A new complex number with value equal to the arc cosine of the given complex number.
      • acosh

        public final Complex acosh()
        Return the principal hyperbolic arc cosine of this complex number. This is defined by:
           acosh(z) = log(z + sqrt(z*z - 1))
          
        where z is this complex number.
        Returns:
        A new complex number with value equal to the principal hyperbolic arc cosine of this complex number.
      • acosh

        public static Complex acosh​(Complex z)
        Return the principal hyperbolic arc cosine of the given complex number. This is defined by:
           acosh(z) = log(z + sqrt(z*z - 1))
          
        where z is this complex number.
        Parameters:
        z - A complex number.
        Returns:
        A new complex number with value equal to the principal hyperbolic arc cosine of this complex number.
      • add

        public final Complex add​(Complex z)
        Return the sum of this complex number and the argument z.
        Parameters:
        z - A complex number.
        Returns:
        A new complex number equal to the sume of the given complex number and the argument.
      • angle

        public final double angle()
        Return the angle or argument of this complex number.
        Returns:
        A double in the range -pi to pi.
      • angle

        public static double angle​(Complex z)
        Return the angle or argument of this complex number.
        Parameters:
        z - A complex number.
        Returns:
        A double in the range -pi to pi.
      • asin

        public final Complex asin()
        Return the principal arc sine of this complex number. This is defined by:
           asin(z) = -i * log(i*z + sqrt(1 - z*z))
          
        where z is this complex number.
        Returns:
        A new complex number equal to the principal arc sine of this complex number.
      • asin

        public static Complex asin​(Complex z)
        Return the principal arc sine of the given complex number. This is defined by:
           asin(z) = -i * log(i*z + sqrt(1 - z*z))
          
        where z is this complex number.
        Parameters:
        z - A complex number.
        Returns:
        A new complex number equal to the principal arc sine of this complex number.
      • asinh

        public final Complex asinh()
        Return the principal hyperbolic arc sine of this complex number. This is defined by:
           asinh(z) = log(z + sqrt(z*z + 1))
          
        where z is this complex number.
        Returns:
        A new complex number with value equal to the principal hyperbolic arc sine of this complex number.
      • asinh

        public static Complex asinh​(Complex z)
        Return the principal hyperbolic arc sine of the given complex number. This is defined by:
           asinh(z) = log(z + sqrt(z*z + 1))
          
        where z is this complex number.
        Parameters:
        z - A complex number.
        Returns:
        A new complex number with value equal to the principal hyperbolic arc sine of this complex number.
      • atan

        public final Complex atan()
        Return the principal arc tangent of this complex number. This is defined by:
          atan(z) = -i/2 * log((i-z)/(i+z))
          
        where z is this complex number.
        Returns:
        a new complex number with value equal to the principal arc tangent of this complex number.
      • atan

        public static Complex atan​(Complex z)
        Return the principal arc tangent of the given complex number. This is defined by:
          atan(z) = -i/2 * log((i-z)/(i+z))
          
        where z is this complex number.
        Parameters:
        z - A complex number.
        Returns:
        a new complex number with value equal to the principal arc tangent of this complex number.
      • atanh

        public final Complex atanh()
        Return the principal hyperbolic arc tangent of this complex number. This is defined by:
           atanh(z) = 1/2 * log((1+z)/(1-z))
          
        where z is this complex number.
        Returns:
        a new complex number with value equal to the principal hyperbolic arc tangent of this complex number.
      • atanh

        public static Complex atanh​(Complex z)
        Return the principal hyperbolic arc tangent of the given complex number. This is defined by:
           atanh(z) = 1/2 * log((1+z)/(1-z))
          
        where z is this complex number.
        Parameters:
        z - A complex number.
        Returns:
        a new complex number with value equal to the principal hyperbolic arc tangent of this complex number.
      • conjugate

        public final Complex conjugate()
        Return the complex conjugate of this complex number.
        Returns:
        A new Complex with value equal to the complex conjugate of of this complex number.
      • conjugate

        public static final Complex conjugate​(Complex z)
        Return the complex conjugate of the specified complex number.
        Parameters:
        z - The specified complex number.
        Returns:
        A new Complex with value equal to the complex conjugate of of the specified complex number.
      • conjugate

        public static final Complex conjugate​(double z)
        Return the complex conjugate of the specified real number, which is just the real number itself. This method is provided for completeness in the expression language.
        Parameters:
        z - The specified real number.
        Returns:
        The number provided as an argument, but converted to complex.
      • cos

        public final Complex cos()
        Return the cosine of this complex number. This is defined by:
          cos(z) = (exp(i*z) + exp(-i*z))/2
          
        where z is this complex number.
        Returns:
        a new complex number with value equal to the cosine of this complex number.
      • cos

        public static Complex cos​(Complex z)
        Return the cosine of the given complex number. This is defined by:
          cos(z) = (exp(i*z) + exp(-i*z))/2
          
        where z is this complex number.
        Parameters:
        z - A complex number.
        Returns:
        a new complex number with value equal to the cosine of this complex number.
      • cosh

        public final Complex cosh()
        Return the hyperbolic cosine of this complex number. This is defined by:
          cosh(z) = (exp(z) + exp(-z))/2
          
        where z is this complex number.
        Returns:
        A new complex number with value equal to the hyperbolic cosine of this complex number.
      • cosh

        public static Complex cosh​(Complex z)
        Return the hyperbolic cosine of the given complex number. This is defined by:
          cosh(z) = (exp(z) + exp(-z))/2
          
        where z is this complex number.
        Parameters:
        z - A complex number.
        Returns:
        A new complex number with value equal to the hyperbolic cosine of this complex number.
      • cot

        public final Complex cot()
        Return the cotangent of this complex number. This is simply:
          cot(z) = 1/tan(z)
          
        where z is this complex number.
        Returns:
        A new complex number with value equal to the cotangent of this complex number.
      • cot

        public static Complex cot​(Complex z)
        Return the cotangent of the given complex number. This is simply:
          cot(z) = 1/tan(z)
          
        where z is this complex number.
        Parameters:
        z - A complex number.
        Returns:
        A new complex number with value equal to the cotangent of this complex number.
      • csc

        public Complex csc()
        Return the cosecant of this complex number. This is simply:
          csc(z) = 1/sin(z)
          
        where z is this complex number.
        Returns:
        A new complex number with value equal to the cosecant of this complex number.
      • csc

        public static Complex csc​(Complex z)
        Return the cosecant of the given complex number. This is simply:
          csc(z) = 1/sin(z)
          
        where z is this complex number.
        Parameters:
        z - A complex number.
        Returns:
        A new complex number with value equal to the cosecant of this complex number.
      • divide

        public final Complex divide​(Complex divisor)
        Divide this complex number by the argument, and return the result in a new Complex object.
        Parameters:
        divisor - The denominator in the division.
        Returns:
        A new complex number equal to this complex number divided by the argument.
      • equals

        public final boolean equals​(java.lang.Object z)
        Return true if the real and imaginary parts of this complex number are equal to those of the argument.
        Overrides:
        equals in class java.lang.Object
        Parameters:
        z - The argument to which this number is being compared.
        Returns:
        True if the real and imaginary parts are equal.
      • exp

        public final Complex exp()
        Return the exponential of this complex number, or ez, where z is this complex number.
        Returns:
        A new complex number with value equal to the exponential of this complex number.
      • exp

        public static Complex exp​(Complex z)
        Return the exponential of the specified complex number, or ez, where z is the argument.
        Parameters:
        z - A complex exponent.
        Returns:
        A new complex number with value equal to the exponential of this complex number.
      • hashCode

        public int hashCode()
        Return a hash code value for this Complex. This method returns the bitwise xor of the hashcode of the real and imaginary parts.
        Overrides:
        hashCode in class java.lang.Object
        Returns:
        A hash code value for this Complex.
      • imag

        public static double imag​(Complex z)
        Return the imaginary part of the specified complex number.
        Parameters:
        z - The complex number.
        Returns:
        The imaginary part of the argument.
      • imag

        public static double imag​(double z)
        Return the imaginary part of the specified real number, which is 0.0.
        Parameters:
        z - The complex number.
        Returns:
        0.0.
      • isCloseTo

        public final boolean isCloseTo​(Complex z)
        Return true if the distance between this complex number and the argument is less than or equal to EPSILON.
        Parameters:
        z - The number to compare against.
        Returns:
        True if the distance to the argument is less than or equal to EPSILON.
        See Also:
        EPSILON
      • isCloseTo

        public final boolean isCloseTo​(Complex z,
                                       double distance)
        Return true if the distance between this complex number and the first argument is less than or equal to the second argument. If the distance argument is negative, return false.
        Parameters:
        z - The number to compare against.
        distance - The distance criterion.
        Returns:
        True if the distance to the first argument is less than or equal to the second argument.
      • isInfinite

        public final boolean isInfinite()
        Return true if either the real or imaginary part is infinite. This is determined by the isInfinite() method of the java.lang.Double class.
        Returns:
        True if this is infinite.
      • isInfinite

        public static boolean isInfinite​(Complex z)
        Return true if either the real or imaginary part of the given complex number is infinite. This is determined by the isInfinite() method of the java.lang.Double class.
        Parameters:
        z - A complex number.
        Returns:
        True if this is infinite.
      • isNaN

        public final boolean isNaN()
        Return true if either the real or imaginary part is NaN. NaN means "not a number," per the IEEE floating point standard. This is determined by the isNaN() method of the java.lang.Double class.
        Returns:
        True if this is NaN.
      • isNaN

        public static boolean isNaN​(Complex z)
        Return true if either the real or imaginary part of the given Complex number is NaN. NaN means "not a number," per the IEEE floating point standard. This is determined by the isNaN() method of the java.lang.Double class.
        Parameters:
        z - A complex number.
        Returns:
        True if this is NaN.
      • log

        public final Complex log()
        Return the natural logarithm of this complex number. The principal value is returned, which is
          log(z) = log(abs(z)) + i * angle(z)
          
        where z is this complex number, abs(z) is its magnitude, and angle(z) is its angle.
        Returns:
        A new complex number with value equal to the natural logarithm of this complex number.
      • log

        public static Complex log​(Complex z)
        Return the natural logarithm of the specified complex number. The principal value is returned, which is
          log(z) = log(abs(z)) + i * angle(z)
          
        where z is this complex number, abs(z) is its magnitude, and angle(z) is its angle.
        Parameters:
        z - A complex number.
        Returns:
        A new complex number with value equal to the natural logarithm of this complex number.
      • magnitude

        public final double magnitude()
        Return the magnitude or absolute value of this complex number.
        Returns:
        A non-negative number that is the absolute value of this complex number.
      • magnitude

        public static double magnitude​(Complex z)
        Return the magnitude or absolute value of the given complex number.
        Parameters:
        z - A complex number.
        Returns:
        A non-negative number that is the absolute value of this complex number.
      • magnitudeSquared

        public double magnitudeSquared()
        Return the square of the magnitude of this complex number. This is provided for efficiency, since it is considerably easier to compute than the magnitude (which is the square root of this result).
        Returns:
        A non-negative number which is the magnitude of this complex number.
      • magnitudeSquared

        public static double magnitudeSquared​(Complex z)
        Return the square of the magnitude of this complex number. This is provided for efficiency, since it is considerably easier to compute than the magnitude (which is the square root of this result).
        Parameters:
        z - A complex number.
        Returns:
        A non-negative number which is the magnitude of this complex number.
      • multiply

        public Complex multiply​(Complex w)
        Return a new complex number that is formed by multiplying this complex number by the specified complex number.
        Parameters:
        w - The specified complex number.
        Returns:
        A new complex number which is the product of this complex number and the specified complex number.
        See Also:
        scale(double)
      • negate

        public final Complex negate()
        Negate this complex number.
        Returns:
        A new complex number that is formed by taking the negatives of both the real and imaginary parts of this complex number.
      • polarToComplex

        public static Complex polarToComplex​(double magnitude,
                                             double angle)
        Return a new complex number with the specified magnitude and angle.
        Parameters:
        magnitude - The magnitude.
        angle - The angle.
        Returns:
        A new complex number with the specified magnitude and angle.
      • pow

        public Complex pow​(double y)
        Return a new complex number with value z y where z is this complex number and y is the argument, a double.
        Parameters:
        y - The exponent, which is a double.
        Returns:
        A new complex number that with value z y.
      • pow

        public static Complex pow​(Complex z,
                                  double y)
        Return a new complex number with value z y where z is the first argument and y is the second argument.
        Parameters:
        z - The number to be raised to a power.
        y - The exponent.
        Returns:
        A new complex number that with value z y.
      • pow

        public final Complex pow​(Complex y)
        Return zy where z is this complex number and y is the argument, a Complex.
        Parameters:
        y - The exponent, which is a complex number.
        Returns:
        A new complex number equal to zy.
      • pow

        public static Complex pow​(Complex z,
                                  Complex y)
        Return a new complex number with value z y where z is the first argument and y is the second argument.
        Parameters:
        z - The number to be raised to a power.
        y - The exponent.
        Returns:
        A new complex number that with value z y.
      • pow

        public static Complex pow​(double z,
                                  Complex y)
        Return a new complex number with value z y where z is the first argument and y is the second argument.
        Parameters:
        z - The number to be raised to a power.
        y - The exponent.
        Returns:
        A new complex number that with value z y.
      • real

        public static double real​(Complex z)
        Return the real part of the specified complex number.
        Parameters:
        z - The complex number.
        Returns:
        The real part of the argument.
      • real

        public static double real​(double z)
        Return the real part of the specified real number, which is the real number itself.
        Parameters:
        z - The complex number.
        Returns:
        The argument.
      • reciprocal

        public final Complex reciprocal()
        Return the reciprocal of this complex number. The result 1/a is given by (a*)/|a|^2.
        Returns:
        A new complex number that is the reciprocal of this one.
      • reciprocal

        public static Complex reciprocal​(Complex z)
        Return the reciprocal of this complex number. The result 1/a is given by (a*)/|a|^2.
        Parameters:
        z - A complex number.
        Returns:
        A new complex number that is the reciprocal of this one.
      • roots

        public final Complex[] roots​(int n)
        Return the nth roots of this complex number in an array. There are n of them, computed by : r1/n(cos((theta + 2kPI) / n + i sin((theta + 2kPI)/n) where k is the index of the returned array. If n is not greater than or equal to one, throw a IllegalArgumentException.
        Parameters:
        n - An integer that must be greater than or equal to one.
        Returns:
        An array of Complex numbers, containing the n roots.
      • roots

        public static Complex[] roots​(Complex z,
                                      int n)
        Return the nth roots of the given complex number in an array. There are n of them, computed by : r1/n(cos((theta + 2kPI) / n + i sin((theta + 2kPI)/n) where k is the index of the returned array. If n is not greater than or equal to one, throw a IllegalArgumentException.
        Parameters:
        z - A complex number.
        n - An integer that must be greater than or equal to one.
        Returns:
        An array of Complex numbers, containing the n roots.
      • scale

        public final Complex scale​(double scalar)
        Return a new complex number with value equal to the product of this complex number and the real argument.
        Parameters:
        scalar - A real number.
        Returns:
        A new complex number with value equal to the product of this complex number and the real argument.
        See Also:
        multiply(ptolemy.math.Complex)
      • sec

        public Complex sec()
        Return a new complex number with value equal to the secant of this complex number. This is simply:
          sec(z) = 1/cos(z)
          
        where z is this complex number.
        Returns:
        A new complex number equal to the secant of this complex number.
      • sec

        public static Complex sec​(Complex z)
        Return a new complex number with value equal to the secant of the given complex number. This is simply:
          sec(z) = 1/cos(z)
          
        where z is this complex number.
        Parameters:
        z - A complex number.
        Returns:
        A new complex number equal to the secant of this complex number.
      • sin

        public final Complex sin()
        Return a new complex number with value equal to the sine of this complex number. This is defined by:
          sin(z) = (exp(i*z) - exp(-i*z))/(2*i)
          
        where z is this complex number.
        Returns:
        A new complex number equal to the sine of this complex number.
      • sin

        public static Complex sin​(Complex z)
        Return a new complex number with value equal to the sine of the given complex number. This is defined by:
          sin(z) = (exp(i*z) - exp(-i*z))/(2*i)
          
        where z is this complex number.
        Parameters:
        z - A complex number.
        Returns:
        A new complex number equal to the sine of this complex number.
      • sinh

        public final Complex sinh()
        Return a new complex number with value equal to the hyperbolic sine of this complex number. This is defined by:
          sinh(z) = (exp(z) - exp(-z))/2
          
        where z is this complex number.
        Returns:
        A new complex number equal to the hyperbolic sine of this complex number.
      • sinh

        public static Complex sinh​(Complex z)
        Return a new complex number with value equal to the hyperbolic sine of this complex number. This is defined by:
          sinh(z) = (exp(z) - exp(-z))/2
          
        where z is this complex number.
        Parameters:
        z - A complex number.
        Returns:
        A new complex number equal to the hyperbolic sine of this complex number.
      • sqrt

        public final Complex sqrt()
        Return a new complex number with its value equal to the the square root of this complex number. The square root is defined to be:
          sqrt(z) = sqrt(mag(z))*(cos(angle(z)/2) + i * sin(angle(z)/2) )
          
        where z is this complex number.
        Returns:
        A new complex number equal to the square root of this complex number.
      • sqrt

        public static Complex sqrt​(Complex z)
        Return a new complex number with its value equal to the the square root of the specified complex number. The square root is defined to be:
          sqrt(z) = sqrt(mag(z))*(cos(angle(z)/2) + i * sin(angle(z)/2) )
          
        where z is this complex number.
        Parameters:
        z - A complex number.
        Returns:
        A new complex number equal to the square root of this complex number.
      • subtract

        public final Complex subtract​(Complex w)
        Return a new complex number formed by subtracting the specified complex number from this complex number.
        Parameters:
        w - The number that is being subtracted.
        Returns:
        A new complex number formed by subtracting the specified complex number from this complex number.
      • tan

        public final Complex tan()
        Return a new complex number with value equal to the tangent of this complex number. This is defined by:
          tan(z) = sin(z)/cos(z)
          
        where z is this complex number.
        Returns:
        A new complex number equal to sin(z)/cos(z).
      • tan

        public static Complex tan​(Complex z)
        Return a new complex number with value equal to the tangent of the given complex number. This is defined by:
          tan(z) = sin(z)/cos(z)
          
        where z is this complex number.
        Parameters:
        z - A complex number.
        Returns:
        A new complex number equal to sin(z)/cos(z).
      • tanh

        public final Complex tanh()
        Return a new complex number with value equal to the hyperbolic tangent of this complex number. This is defined by:
          tanh(z) = sinh(z)/cosh(z)
          
        where z is this complex number.
        Returns:
        A new complex number equal to sinh(z)/cosh(z).
      • tanh

        public static Complex tanh​(Complex z)
        Return a new complex number with value equal to the hyperbolic tangent of the given complex number. This is defined by:
          tanh(z) = sinh(z)/cosh(z)
          
        where z is this complex number.
        Parameters:
        z - A complex number.
        Returns:
        A new complex number equal to sinh(z)/cosh(z).
      • toString

        public final java.lang.String toString()
        Return a string representation of this Complex.
        Overrides:
        toString in class java.lang.Object
        Returns:
        A string of the form "x + yi".
      • toString

        public static java.lang.String toString​(Complex value)
        Return a string representation of the given Complex.
        Parameters:
        value - The given value.
        Returns:
        A string of the form "x + yi".