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

📄 z.java

📁 JAVA 数学程序库 提供常规的数值计算程序包
💻 JAVA
📖 第 1 页 / 共 4 页
字号:

    /**
    * Returns the hyperbolic tangent of a <tt>Complex</tt> number.
    *
    * <p>
    * <pre>
    *     tanh(z)  =  sinh(z) / cosh(z)
    * </pre>
    * <p>
    * @return                  The <tt>Complex</tt> hyperbolic tangent
    * <p>
    * @see                     Complex#tan()
    * @see                     Complex#atanh()
    **/
    public Z tanh () 
    {
        Z result;
        //  tanh(z)  =  sinh(z) / cosh(z)

        double scalar;
        double _re1, _im1;
        double _re2, _im2;
        double _re3, _im3;

        double ch_re, ch_im;

        // sinh() ...

        // _1:      z.exp() ...
        scalar =  Math.exp(re);
        _re1 =  scalar * Math.cos(im);
        _im1 =  scalar * Math.sin(im);

        // _2:      z.neg().exp() ...
        scalar =  Math.exp(-re);
        _re2 =  scalar * Math.cos(-im);
        _im2 =  scalar * Math.sin(-im);

        // _3:      _1.Minus(_2) ...
        _re3 =  _re1 - _re2;
        _im3 =  _im1 - _im2;

        // result:  _3.scale(0.5) ...
        result =  cart(0.5*_re3, 0.5*_im3);

        // cosh() ...

        // _3:      _1.Plus(_2) ...
        _re3 =  _re1 + _re2;
        _im3 =  _im1 + _im2;

        // ch:      _3.scale(0.5) ...
        ch_re =  0.5 * _re3;
        ch_im =  0.5 * _im3;

        // result:  result.Div(ch) ...
        Div(result, ch_re, ch_im);
        return  result;
    }//end tanh()

    /**
    * Returns the <i>principal</i> arc sine of a <tt>Complex</tt> number.
    *
    * <p>
    * <pre>
    *     asin(z)  =  -<i><b>i</b></i> * log(<i><b>i</b></i>*z + Sqrt(1 - z*z))
    * </pre>
    * <p>
    * There are infinitely many solutions, besides the principal solution.
    * If <b>A</b> is the principal solution of <i>asin(z)</i>, the others are
    * of the form:
    * <p>
    * <pre>
    *     k*<b>PI</b> + (-1)<sup><font size=-1>k</font></sup>  * <b>A</b>
    * </pre>
    * <p>
    * where k is any integer.
    * <p>
    * @return                  Principal <tt>Complex</tt> arc sine
    * <p>
    * @see                     Complex#sin()
    * @see                     Complex#sinh()
    **/

    public Z asin () 
    {
        Z result;
        //  asin(z)  =  -i * log(i*z + Sqrt(1 - z*z))

        double _re1, _im1;

        // _1:      one.Minus(z.Times(z)) ...
        _re1 =  1.0 - ( (re*re) - (im*im) );
        _im1 =  0.0 - ( (re*im) + (im*re) );

        // result:  _1.Sqrt() ...
        result =  cart(_re1, _im1);
        Sqrt(result);

        // _1:      z.Times(i) ...
        _re1 =  - im;
        _im1 =  + re;

        // result:  _1.Plus(result) ...
        result.re =  _re1 + result.re;
        result.im =  _im1 + result.im;

        // _1:      result.log() ...
        _re1 =  Math.log(result.abs());
        _im1 =  result.arg();

        // result:  i.neg().Times(_1) ...
        result.re =    _im1;
        result.im =  - _re1;
        return  result;
    }

    /**
    * Returns the <i>principal</i> arc cosine of a <tt>Complex</tt> number.
    *
    * <p>
    * <pre>
    *     acos(z)  =  -<i><b>i</b></i> * log( z + <i><b>i</b></i> * Sqrt(1 - z*z) )
    * </pre>
    * <p>
    * There are infinitely many solutions, besides the principal solution.
    * If <b>A</b> is the principal solution of <i>acos(z)</i>, the others are
    * of the form:
    * <p>
    * <pre>
    *     2*k*<b>PI</b> +/- <b>A</b>
    * </pre>
    * <p>
    * where k is any integer.
    * <p>
    * @return                  Principal <tt>Complex</tt> arc cosine
    * <p>
    * @see                     Complex#cos()
    * @see                     Complex#cosh()
    **/
    public Z acos () 
    {
        Z result;
        //  acos(z)  =  -i * log( z + i * Sqrt(1 - z*z) )

        double _re1, _im1;

        // _1:      one.Minus(z.Times(z)) ...
        _re1 =  1.0 - ( (re*re) - (im*im) );
        _im1 =  0.0 - ( (re*im) + (im*re) );

        // result:  _1.Sqrt() ...
        result =  cart(_re1, _im1);
        Sqrt(result);

        // _1:      i.Times(result) ...
        _re1 =  - result.im;
        _im1 =  + result.re;

        // result:  z.Plus(_1) ...
        result.re =  re + _re1;
        result.im =  im + _im1;

        // _1:      result.log()
        _re1 =  Math.log(result.abs());
        _im1 =  result.arg();

        // result:  i.neg().Times(_1) ...
        result.re =    _im1;
        result.im =  - _re1;
        return  result;
    }

    /**
    * Returns the <i>principal</i> arc tangent of a <tt>Complex</tt> number.
    *
    * <p>
    * <pre>
    *     atan(z)  =  -<i><b>i</b></i>/2 * log( (<i><b>i</b></i>-z)/(<i><b>i</b></i>+z) )
    * </pre>
    * <p>
    * There are infinitely many solutions, besides the principal solution.
    * If <b>A</b> is the principal solution of <i>atan(z)</i>, the others are
    * of the form:
    * <p>
    * <pre>
    *     <b>A</b> + k*<b>PI</b>
    * </pre>
    * <p>
    * where k is any integer.
    * <p>
    * <i><b>Domain Restrictions:</b><ul> atan(z) is undefined for z = + <b>i</b> or z = - <b>i</b>
    * </ul></i>
    * <p>
    * @return                  Principal <tt>Complex</tt> arc tangent
    * <p>
    * @see                     Complex#tan()
    * @see                     Complex#tanh()
    **/
    public Z atan () 
    {
        Z result;
        //  atan(z)  =  -i/2 * log( (i-z)/(i+z) )

        double _re1, _im1;

        // result:  i.Minus(z) ...
        result =  cart(- re, 1.0 - im);

        // _1:      i.Plus(z) ...
        _re1 =  + re;
        _im1 =  1.0 + im;

        // result:  result.Div(_1) ...
        Div(result, _re1, _im1);

        // _1:      result.log() ...
        _re1 =  Math.log(result.abs());
        _im1 =  result.arg();

        // result:  half_i.neg().Times(_2) ...
        result.re =   0.5*_im1;
        result.im =  -0.5*_re1;
        return  result;
    }

    /**
    * Returns the <i>principal</i> inverse hyperbolic sine of a
    * <tt>Complex</tt> number.
    *
    * <p>
    * <pre>
    *     asinh(z)  =  log(z + Sqrt(z*z + 1))
    * </pre>
    * <p>
    * There are infinitely many solutions, besides the principal solution.
    * If <b>A</b> is the principal solution of <i>asinh(z)</i>, the others are
    * of the form:
    * <p>
    * <pre>
    *     k*<b>PI</b>*<b><i>i</i></b> + (-1)<sup><font size=-1>k</font></sup>  * <b>A</b>
    * </pre>
    * <p>
    * where k is any integer.
    * <p>
    * @return                  Principal <tt>Complex</tt> inverse hyperbolic sine
    * <p>
    * @see                     Complex#sinh()
    **/
    public Z asinh () 
    {
        Z result;
        //  asinh(z)  =  log(z + Sqrt(z*z + 1))

        double _re1, _im1;

        // _1:      z.Times(z).Plus(one) ...
        _re1 =  ( (re*re) - (im*im) ) + 1.0;
        _im1 =  ( (re*im) + (im*re) ) + 0.0;

        // result:  _1.Sqrt() ...
        result =  cart(_re1, _im1);
        Sqrt(result);

        // result:  z.Plus(result) ...
        result.re =  re + result.re;                                       // !
        result.im =  im + result.im;                                       // !

        // _1:      result.log() ...
        _re1 =  Math.log(result.abs());
        _im1 =  result.arg();

        // result:  _1 ...
        result.re =  _re1;
        result.im =  _im1;

        /*
        * Many thanks to the mathematicians of aus.mathematics and sci.math,
        * and to Zdislav V. Kovarik of the  Department  of  Mathematics  and
        * Statistics,     McMaster     University     and    John    McGowan
        * <jmcgowan@inch.com> in particular, for their advice on the current
        * naming conventions for "area/argumentus sinus hyperbolicus".
        */

        return  result;
    }//end asinh()

    /**
    * Returns the <i>principal</i> inverse hyperbolic cosine of a
    * <tt>Complex</tt> number.
    *
    * <p>
    * <pre>
    *     acosh(z)  =  log(z + Sqrt(z*z - 1))
    * </pre>
    * <p>
    * There are infinitely many solutions, besides the principal solution.
    * If <b>A</b> is the principal solution of <i>acosh(z)</i>, the others are
    * of the form:
    * <p>
    * <pre>
    *     2*k*<b>PI</b>*<b><i>i</i></b> +/- <b>A</b>
    * </pre>
    * <p>
    * where k is any integer.
    * <p>
    * @return                  Principal <tt>Complex</tt> inverse hyperbolic cosine
    * <p>
    * @see                     Complex#cosh()
    **/
    public Z acosh() 
    {
        Z result;
        //  acosh(z)  =  log(z + Sqrt(z*z - 1))

        double _re1, _im1;

        // _1:  z.Times(z).Minus(one) ...
        _re1 =  ( (re*re) - (im*im) ) - 1.0;
        _im1 =  ( (re*im) + (im*re) ) - 0.0;

        // result:  _1.Sqrt() ...
        result =  cart(_re1, _im1);
        Sqrt(result);

        // result:  z.Plus(result) ...
        result.re =  re + result.re;                                       // !
        result.im =  im + result.im;                                       // !

        // _1:  result.log() ...
        _re1 =  Math.log(result.abs());
        _im1 =  result.arg();

        // result:  _1 ...
        result.re =  _re1;
        result.im =  _im1;
        return  result;
    }//end acosh()


    /**
    * Returns the <i>principal</i> inverse hyperbolic tangent of a
    * <tt>Complex</tt> number.
    *
    * <p>
    * <pre>
    *     atanh(z)  =  1/2 * log( (1+z)/(1-z) )
    * </pre>
    * <p>
    * There are infinitely many solutions, besides the principal solution.
    * If <b>A</b> is the principal solution of <i>atanh(z)</i>, the others are
    * of the form:
    * <p>
    * <pre>
    *     <b>A</b> + k*<b>PI</b>*<b><i>i</i></b>
    * </pre>
    * <p>
    * where k is any integer.
    * <p>
    * <i><b>Domain Restrictions:</b><ul> atanh(z) is undefined for z = + 1 or z = - 1
    * </ul></i>
    * <p>
    * @return                  Principal <tt>Complex</tt> inverse hyperbolic tangent
    * <p>
    * @see                     Complex#tanh()
    **/
    public Z atanh () 
    {
        Z result;
        //  atanh(z)  =  1/2 * log( (1+z)/(1-z) )

        double _re1, _im1;

        // result:  one.Plus(z) ...
        result =  cart(1.0 + re, + im);

        // _1:      one.Minus(z) ...
        _re1 =  1.0 - re;
        _im1 =  - im;

        // result:  result.Div(_1) ...
        Div(result, _re1, _im1);

        // _1:      result.log() ...
        _re1 =  Math.log(result.abs());
        _im1 =  result.arg();

        // result:  _1.scale(0.5) ...
        result.re =  0.5 * _re1;
        result.im =  0.5 * _im1;
        return  result;
    }

    /**
    * Converts a <tt>Complex</tt> into a {@link java.lang.String <tt>String</tt>} of the form
    * <tt>(</tt><i>a</i><tt> + </tt><i>b</i><tt>i)</tt>.
    *
    * <p>
    * This enables a <tt>Complex</tt> to be easily printed.  For example, if
    * <tt>z</tt> was <i>2 - 5<b>i</b></i>, then
    * <pre>
    *     System.out.println("z = " + z);
    * </pre>
    * would print something like
    * <pre>
    *     z = (2.0 - 5.0i)
    * </pre>
    * <!--
    * <i><b>Note:</b><ul>Concatenating {@link java.lang.String <tt>String</tt>}s, using a system
    * overloaded meaning of the "<tt>+</tt>" operator, in fact causes the
    * <tt>toString()</tt> method to be invoked on the object <tt>z</tt> at
    * runtime.</ul></i>
    * -->
    * <p>
    * @return                  {@link java.lang.String <tt>String</tt>} containing the cartesian coordinate representation
    * <p>
    * @see                     Complex#cart(double, double)
    **/
    public String toString () 
    {
        StringBuffer result =  new StringBuffer();
        if(im != 0)
        	result.append("(");
        result.append(numFormat.format(re));

        if (im < 0.0) 
        {                                                        // ...remembering NaN & Infinity
            result.append(" - ").append(numFormat.format(-im));
	        result.append("i)");
        } 
        else if (1.0 / im == Double.NEGATIVE_INFINITY) 
        {
        } 
        else if(im > 0)
        {
            result.append(" + ").append(numFormat.format(+im));
	        result.append("i)");
        }

        return  result.toString();
    }//end toString()

/**
 * Interchanges the real and imaginary parts of two Z's.

   @param     a a Z
   @return    this = a, with a set to the original
              value of this.
*/

   public Z Exch(Z a){
      double t;
      t = re; re = a.re; a.re = t;
      t = im; im = a.im; a.im = t;
      return this;
   }
   
   public Z Eq(Z a){
   		re = a.re;
   		im = a.im;
   		return this;
   }
}




/*           Jim Shapiro <jnshapi@argo.ecte.uswc.uswest.com>


                           Priyantha Jayanetti
                       ---------------------------
                       email: pidge@eece.maine.edu

               Dept.  of Electrical & Computer Engineering
                       University of Maine,  Orono


                            Mr.  Daniel Hirsch
                     <R.D.Hirsch@red-deer.demon.co.uk>


/*             C A U T I O N   E X P L O S I V E   B O L T S
--                     REMOVE BEFORE ENGAGING REPLY
//
// Kelly and Sandy Anderson <kelsan@explosive-alma-services-bolts.co.uk>
// (alternatively            kelsan_odoodle at ya who period, see oh em)
// Alexander (Sandy)  1B5A DF3D A3D9 B932 39EB  3F1B 981F 4110 27E1 64A4
// Kelly              673F 6751 6DBA 196F E8A8  6D87 4AEC F35E E9AD 099B
// Homepages             http://www.explosive-alma-services-bolts.co.uk/
*/

⌨️ 快捷键说明

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