快速三角函数tangent算法[matlab]

function t = tangent(z); % z 输入的角度

N = 12; % 循环系数
m = [1,-1];

d = [2,1,0.5,0.25,0.125,0.0625,0.03125,0.015625,0.0078125,0.00390625,...
    0.001953125,0.0009765625];%d[N]=2^(-k)
det = [90,45,26.565051,14.036243,7.125016,3.576334,1.789911,0.895174,0.447614,...
    0.223811,0.111906,0.055953];% 角增量
xi = 0.60725;% x的中间变量,xi初始值为放大率的倒数
yi = 0; % y的中间变量

for k = 1:N
    if z < 0
        p(k) = m(2); % 判断旋转方向  
    else
        p(k) = m(1);
    end
    if k > 1
        z = z - p(k)*det(k);
        x = xi + d(k)*p(k)*yi;
        y = yi - d(k)*p(k)*xi;
        xi = x;
        yi = y;
    else %第一次迭代
        z = z - p(k)*det(k);
        x = p(k)*yi;
        y = -p(k)*xi;
    end
end

t = x/y ;

你可能感兴趣的:(算法,function,matlab)