类 Complex


  • public class Complex
    extends java.lang.Object
    The Complex class represents a complex number. Complex numbers are immutable: their values cannot be changed after they are created. It includes methods for addition, subtraction, multiplication, division, conjugation, and other common functions on complex numbers.

    For additional documentation, see Section 9.9 of Algorithms, 4th Edition by Robert Sedgewick and Kevin Wayne.

    • 构造器概要

      构造器 
      构造器 说明
      Complex​(double real, double imag)
      Initializes a complex number from the specified real and imaginary parts.
    • 方法概要

      修饰符和类型 方法 说明
      double abs()
      Returns the absolute value of this complex number.
      Complex conjugate()
      Returns the complex conjugate of this complex number.
      Complex cos()
      Returns the complex cosine of this complex number.
      Complex divides​(Complex that)
      Returns the result of dividing the specified complex number into this complex number.
      Complex exp()
      Returns the complex exponential of this complex number.
      double im()
      Returns the imaginary part of this complex number.
      static void main​(java.lang.String[] args)
      Unit tests the Complex data type.
      Complex minus​(Complex that)
      Returns the result of subtracting the specified complex number from this complex number.
      double phase()
      Returns the phase of this complex number.
      Complex plus​(Complex that)
      Returns the sum of this complex number and the specified complex number.
      double re()
      Returns the real part of this complex number.
      Complex reciprocal()
      Returns the reciprocal of this complex number.
      Complex scale​(double alpha)
      Returns the product of this complex number and the specified scalar.
      Complex sin()
      Returns the complex sine of this complex number.
      Complex tan()
      Returns the complex tangent of this complex number.
      Complex times​(double alpha)
      已过时。
      Replaced by scale(double).
      Complex times​(Complex that)
      Returns the product of this complex number and the specified complex number.
      java.lang.String toString()
      Returns a string representation of this complex number.
      • 从类继承的方法 java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • 构造器详细资料

      • Complex

        public Complex​(double real,
                       double imag)
        Initializes a complex number from the specified real and imaginary parts.
        参数:
        real - the real part
        imag - the imaginary part
    • 方法详细资料

      • toString

        public java.lang.String toString()
        Returns a string representation of this complex number.
        覆盖:
        toString 在类中 java.lang.Object
        返回:
        a string representation of this complex number, of the form 34 - 56i.
      • abs

        public double abs()
        Returns the absolute value of this complex number. This quantity is also known as the modulus or magnitude.
        返回:
        the absolute value of this complex number
      • phase

        public double phase()
        Returns the phase of this complex number. This quantity is also known as the angle or argument.
        返回:
        the phase of this complex number, a real number between -pi and pi
      • plus

        public Complex plus​(Complex that)
        Returns the sum of this complex number and the specified complex number.
        参数:
        that - the other complex number
        返回:
        the complex number whose value is (this + that)
      • minus

        public Complex minus​(Complex that)
        Returns the result of subtracting the specified complex number from this complex number.
        参数:
        that - the other complex number
        返回:
        the complex number whose value is (this - that)
      • times

        public Complex times​(Complex that)
        Returns the product of this complex number and the specified complex number.
        参数:
        that - the other complex number
        返回:
        the complex number whose value is (this * that)
      • scale

        public Complex scale​(double alpha)
        Returns the product of this complex number and the specified scalar.
        参数:
        alpha - the scalar
        返回:
        the complex number whose value is (alpha * this)
      • times

        @Deprecated
        public Complex times​(double alpha)
        已过时。
        Replaced by scale(double).
        Returns the product of this complex number and the specified scalar.
        参数:
        alpha - the scalar
        返回:
        the complex number whose value is (alpha * this)
      • conjugate

        public Complex conjugate()
        Returns the complex conjugate of this complex number.
        返回:
        the complex conjugate of this complex number
      • reciprocal

        public Complex reciprocal()
        Returns the reciprocal of this complex number.
        返回:
        the complex number whose value is (1 / this)
      • re

        public double re()
        Returns the real part of this complex number.
        返回:
        the real part of this complex number
      • im

        public double im()
        Returns the imaginary part of this complex number.
        返回:
        the imaginary part of this complex number
      • divides

        public Complex divides​(Complex that)
        Returns the result of dividing the specified complex number into this complex number.
        参数:
        that - the other complex number
        返回:
        the complex number whose value is (this / that)
      • exp

        public Complex exp()
        Returns the complex exponential of this complex number.
        返回:
        the complex exponential of this complex number
      • sin

        public Complex sin()
        Returns the complex sine of this complex number.
        返回:
        the complex sine of this complex number
      • cos

        public Complex cos()
        Returns the complex cosine of this complex number.
        返回:
        the complex cosine of this complex number
      • tan

        public Complex tan()
        Returns the complex tangent of this complex number.
        返回:
        the complex tangent of this complex number
      • main

        public static void main​(java.lang.String[] args)
        Unit tests the Complex data type.
        参数:
        args - the command-line arguments