⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 complex.java

📁 Apache的common math数学软件包
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
        return imaginary;    }    /**     * Access the real part.     *     * @return the real part     */    public double getReal() {        return real;    }        /**     * Returns true if either or both parts of this complex number is NaN;     * false otherwise     *     * @return  true if either or both parts of this complex number is NaN;     * false otherwise     */    public boolean isNaN() {        return Double.isNaN(real) || Double.isNaN(imaginary);            }        /**     * Returns true if either the real or imaginary part of this complex number     * takes an infinite value (either <code>Double.POSITIVE_INFINITY</code> or      * <code>Double.NEGATIVE_INFINITY</code>) and neither part     * is <code>NaN</code>.     *      * @return true if one or both parts of this complex number are infinite     * and neither part is <code>NaN</code>     */    public boolean isInfinite() {        return !isNaN() &&         (Double.isInfinite(real) || Double.isInfinite(imaginary));            }        /**     * Return the product of this complex number and the given complex number.     * <p>     * Implements preliminary checks for NaN and infinity followed by     * the definitional formula:     * <pre><code>     * (a + bi)(c + di) = (ac - bd) + (ad + bc)i     * </code></pre>     * </p>     * <p>     * Returns {@link #NaN} if either this or <code>rhs</code> has one or more     * NaN parts.     * </p>     * Returns {@link #INF} if neither this nor <code>rhs</code> has one or more     * NaN parts and if either this or <code>rhs</code> has one or more     * infinite parts (same result is returned regardless of the sign of the     * components).     * </p>     * <p>     * Returns finite values in components of the result per the     * definitional formula in all remaining cases.     *  </p>     *      * @param rhs the other complex number     * @return the complex number product     * @throws NullPointerException if <code>rhs</code> is null     */    public Complex multiply(Complex rhs) {        if (isNaN() || rhs.isNaN()) {            return NaN;        }        if (Double.isInfinite(real) || Double.isInfinite(imaginary) ||            Double.isInfinite(rhs.real)|| Double.isInfinite(rhs.imaginary)) {            // we don't use Complex.isInfinite() to avoid testing for NaN again            return INF;        }        return createComplex(real * rhs.real - imaginary * rhs.imaginary,                real * rhs.imaginary + imaginary * rhs.real);    }        /**     * Return the additive inverse of this complex number.     * <p>     * Returns <code>Complex.NaN</code> if either real or imaginary     * part of this Complex number equals <code>Double.NaN</code>.</p>     *     * @return the negation of this complex number     */    public Complex negate() {        if (isNaN()) {            return NaN;        }                return createComplex(-real, -imaginary);    }        /**     * Return the difference between this complex number and the given complex     * number.      * <p>     * Uses the definitional formula      * <pre>     * (a + bi) - (c + di) = (a-c) + (b-d)i     * </pre></p>     * <p>     * If either this or <code>rhs</code> has a NaN value in either part,     * {@link #NaN} is returned; otherwise inifinite and NaN values are     * returned in the parts of the result according to the rules for     * {@link java.lang.Double} arithmetic. </p>     *      * @param rhs the other complex number     * @return the complex number difference     * @throws NullPointerException if <code>rhs</code> is null     */    public Complex subtract(Complex rhs) {        if (isNaN() || rhs.isNaN()) {            return NaN;        }                return createComplex(real - rhs.getReal(),            imaginary - rhs.getImaginary());    }        /**     * Compute the      * <a href="http://mathworld.wolfram.com/InverseCosine.html" TARGET="_top">     * inverse cosine</a> of this complex number.     * <p>     * Implements the formula: <pre>     * <code> acos(z) = -i (log(z + i (sqrt(1 - z<sup>2</sup>))))</code></pre></p>     * <p>     * Returns {@link Complex#NaN} if either real or imaginary part of the      * input argument is <code>NaN</code> or infinite.</p>     *      * @return the inverse cosine of this complex number     * @since 1.2     */    public Complex acos() {        if (isNaN()) {            return Complex.NaN;        }        return this.add(this.sqrt1z().multiply(Complex.I)).log()              .multiply(Complex.I.negate());    }        /**     * Compute the      * <a href="http://mathworld.wolfram.com/InverseSine.html" TARGET="_top">     * inverse sine</a> of this complex number.     * <p>     * Implements the formula: <pre>     * <code> asin(z) = -i (log(sqrt(1 - z<sup>2</sup>) + iz)) </code></pre></p>     * <p>     * Returns {@link Complex#NaN} if either real or imaginary part of the      * input argument is <code>NaN</code> or infinite.</p>     *      * @return the inverse sine of this complex number.     * @since 1.2     */    public Complex asin() {        if (isNaN()) {            return Complex.NaN;        }        return sqrt1z().add(this.multiply(Complex.I)).log()              .multiply(Complex.I.negate());    }        /**     * Compute the      * <a href="http://mathworld.wolfram.com/InverseTangent.html" TARGET="_top">     * inverse tangent</a> of this complex number.     * <p>     * Implements the formula: <pre>     * <code> atan(z) = (i/2) log((i + z)/(i - z)) </code></pre></p>     * <p>     * Returns {@link Complex#NaN} if either real or imaginary part of the      * input argument is <code>NaN</code> or infinite.</p>     *      * @return the inverse tangent of this complex number     * @since 1.2     */    public Complex atan() {        if (isNaN()) {            return Complex.NaN;        }                return this.add(Complex.I).divide(Complex.I.subtract(this)).log()            .multiply(Complex.I.divide(createComplex(2.0, 0.0)));    }        /**     * Compute the      * <a href="http://mathworld.wolfram.com/Cosine.html" TARGET="_top">     * cosine</a>     * of this complex number.     * <p>     * Implements the formula: <pre>     * <code> cos(a + bi) = cos(a)cosh(b) - sin(a)sinh(b)i</code></pre>     * where the (real) functions on the right-hand side are     * {@link java.lang.Math#sin}, {@link java.lang.Math#cos},      * {@link MathUtils#cosh} and {@link MathUtils#sinh}.</p>     * <p>     * Returns {@link Complex#NaN} if either real or imaginary part of the      * input argument is <code>NaN</code>.</p>     * <p>     * Infinite values in real or imaginary parts of the input may result in     * infinite or NaN values returned in parts of the result.<pre>     * Examples:      * <code>     * cos(1 &plusmn; INFINITY i) = 1 &#x2213; INFINITY i     * cos(&plusmn;INFINITY + i) = NaN + NaN i     * cos(&plusmn;INFINITY &plusmn; INFINITY i) = NaN + NaN i</code></pre></p>     *      * @return the cosine of this complex number     * @since 1.2     */    public Complex cos() {        if (isNaN()) {            return Complex.NaN;        }                return createComplex(Math.cos(real) * MathUtils.cosh(imaginary),            -Math.sin(real) * MathUtils.sinh(imaginary));    }        /**     * Compute the      * <a href="http://mathworld.wolfram.com/HyperbolicCosine.html" TARGET="_top">     * hyperbolic cosine</a> of this complex number.     * <p>     * Implements the formula: <pre>     * <code> cosh(a + bi) = cosh(a)cos(b) + sinh(a)sin(b)i</code></pre>     * where the (real) functions on the right-hand side are     * {@link java.lang.Math#sin}, {@link java.lang.Math#cos},      * {@link MathUtils#cosh} and {@link MathUtils#sinh}.</p>     * <p>     * Returns {@link Complex#NaN} if either real or imaginary part of the      * input argument is <code>NaN</code>.</p>     * <p>     * Infinite values in real or imaginary parts of the input may result in     * infinite or NaN values returned in parts of the result.<pre>     * Examples:      * <code>     * cosh(1 &plusmn; INFINITY i) = NaN + NaN i     * cosh(&plusmn;INFINITY + i) = INFINITY &plusmn; INFINITY i     * cosh(&plusmn;INFINITY &plusmn; INFINITY i) = NaN + NaN i</code></pre></p>     *      * @return the hyperbolic cosine of this complex number.     * @since 1.2     */    public Complex cosh() {        if (isNaN()) {            return Complex.NaN;        }                return createComplex(MathUtils.cosh(real) * Math.cos(imaginary),            MathUtils.sinh(real) * Math.sin(imaginary));    }        /**     * Compute the     * <a href="http://mathworld.wolfram.com/ExponentialFunction.html" TARGET="_top">     * exponential function</a> of this complex number.     * <p>     * Implements the formula: <pre>     * <code> exp(a + bi) = exp(a)cos(b) + exp(a)sin(b)i</code></pre>     * where the (real) functions on the right-hand side are     * {@link java.lang.Math#exp}, {@link java.lang.Math#cos}, and     * {@link java.lang.Math#sin}.</p>     * <p>     * Returns {@link Complex#NaN} if either real or imaginary part of the      * input argument is <code>NaN</code>.</p>     * <p>     * Infinite values in real or imaginary parts of the input may result in     * infinite or NaN values returned in parts of the result.<pre>     * Examples:      * <code>     * exp(1 &plusmn; INFINITY i) = NaN + NaN i     * exp(INFINITY + i) = INFINITY + INFINITY i     * exp(-INFINITY + i) = 0 + 0i     * exp(&plusmn;INFINITY &plusmn; INFINITY i) = NaN + NaN i</code></pre></p>     *      * @return <i>e</i><sup><code>this</code></sup>     * @since 1.2     */    public Complex exp() {        if (isNaN()) {            return Complex.NaN;        }                double expReal = Math.exp(real);        return createComplex(expReal *  Math.cos(imaginary), expReal * Math.sin(imaginary));    }        /**

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -