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

📄 tan.java

📁 JAVA 数学程序库 提供常规的数值计算程序包
💻 JAVA
字号:
package jmathlib.toolbox.trigonometric;

import jmathlib.core.functions.ExternalElementWiseFunction;
import jmathlib.core.tokens.numbertokens.DoubleNumberToken;

public class tan extends ExternalElementWiseFunction
{
    
    public tan()
    {
        name = "tan";
    }
    
    /**trigonometric functions - calculate the tangent of this token
    @return the result as an OperandToken*/
    public double[] evaluateValue(double[] arg)
    {
        double[] temp1 = sin(arg);
        double[] temp2 = cos(arg);
        
        DoubleNumberToken t = new DoubleNumberToken();
        double[] result = t.divide(temp1, temp2);

        return result;
    }

    public double[] sin(double[] arg)
    {
        double result[] = new double[2];
        double scalar;
        double iz_re, iz_im;
        double _re1, _im1;
        double _re2, _im2;

        // iz:      i.Times(z) ...
        iz_re =  -arg[IMAG];
        iz_im =   arg[REAL];

        // _1:      iz.exp() ...
        scalar =  Math.exp(iz_re);
        _re1 =  scalar * Math.cos(iz_im);
        _im1 =  scalar * Math.sin(iz_im);

        // _2:      iz.neg().exp() ...
        scalar =  Math.exp(-iz_re);
        _re2 =  scalar * Math.cos(-iz_im);
        _im2 =  scalar * Math.sin(-iz_im);

        // _1:      _1.Minus(_2) ...
        _re1 = _re1 - _re2;                       // !!!
        _im1 = _im1 - _im2;                       // !!!

        // result:  _1.Div(2*i) ...
        result[REAL] =  0.5*_im1;
        result[IMAG] = -0.5*_re1;
        
        return result;
    }

    public double[] cos(double[] arg)
    {
        double result[] = new double[2];
        double scalar;
        double iz_re, iz_im;
        double _re1, _im1;
        double _re2, _im2;

        // iz:      i.Times(z) ...
        iz_re =  -arg[IMAG];
        iz_im =   arg[REAL];

        // _1:      iz.exp() ...
        scalar =  Math.exp(iz_re);
        _re1 =  scalar * Math.cos(iz_im);
        _im1 =  scalar * Math.sin(iz_im);

        // _2:      iz.neg().exp() ...
        scalar =  Math.exp(-iz_re);
        _re2 =  scalar * Math.cos(-iz_im);
        _im2 =  scalar * Math.sin(-iz_im);

        // _1:      _1.Plus(_2) ...
        _re1 = _re1 + _re2;                 // !!!
        _im1 = _im1 + _im2;                 // !!!

        // result:  _1.scale(0.5) ...
        result[REAL] = 0.5*_re1;
        result[IMAG] = -0.5*_im1;
        
        return result;
    }


    
}

/*
@GROUP
trigonometric
@SYNTAX
answer = tan(angle)
@DOC
Returns the tangent of angle.
@EXAMPLES
tan(0) = 0
tan(1) = 1.55740772
@SEE
atan, tanh
*/

⌨️ 快捷键说明

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