📄 testsinecosine_vs.html
字号:
</pre><img vspace="5" hspace="5" src="testSineCosine_VS_05.png"> <h2>test sqrt/atanh<a name="6"></a></h2><pre class="codeinput">alpha=linspace(.5,1,100)';t_sqrt=sqrt(alpha);squreroot=x_sqrt(:,1);figure(5)subplot(221),hold <span class="string">on</span>plot(alpha,t_sqrt,<span class="string">'LineWidth'</span>,3,<span class="string">'Color'</span>,<span class="string">'y'</span>)plot(alpha,squreroot),hold <span class="string">off</span>xlabel(<span class="string">'\alpha'</span>),ylabel(<span class="string">'sqrt(\alpha)'</span>)title(<span class="string">'Cordic & sqrt(\alpha)'</span>)legend(<span class="string">'truth'</span>,<span class="string">'cordic'</span>)subplot(222)plot(alpha,t_sqrt-squreroot,<span class="string">'c'</span>)xlabel(<span class="string">'\alpha'</span>),ylabel(<span class="string">'\Delta\{sqrt(\alpha)\}'</span>)title(<span class="string">'error for sqrt(.)'</span>)<span class="comment">%</span>gamma=linspace(.16,.76,100)';t_atanh=atanh(gamma);arctanh=x_atanh(:,1);subplot(223),hold <span class="string">on</span>plot(gamma,t_atanh,<span class="string">'LineWidth'</span>,3,<span class="string">'Color'</span>,<span class="string">'g'</span>)plot(gamma,arctanh),hold <span class="string">off</span>xlabel(<span class="string">'\gamma'</span>),ylabel(<span class="string">'atanh\gamma'</span>)title(<span class="string">'Cordic & atanh\gamma'</span>)legend(<span class="string">'truth'</span>,<span class="string">'cordic'</span>)subplot(2,2,4)plot(thetah,t_atanh-arctanh,<span class="string">'m'</span>)xlabel(<span class="string">'\gamma'</span>),ylabel(<span class="string">'\Delta\{atanh\gamma\}'</span>)title(<span class="string">'error for atanh(.)'</span>)</pre><img vspace="5" hspace="5" src="testSineCosine_VS_06.png"> <p class="footer"><br> Published with MATLAB® 7.4<br></p> </div> <!--##### SOURCE BEGIN #####%% test sine/cosine
%
theta=linspace(0,pi/2,100)';
sine=x_sin;% datas provided by VS
cosine=x_cos;
t_cos=cos(theta);% true values
t_sin=sin(theta);
figure(1)
subplot(221),hold on % contrast diagram
plot(theta,t_cos,'LineWidth',3,'Color','y')
plot(theta,cosine,'b')
xlim([0 1.6]),hold off
xlabel('\theta'),ylabel('cos\theta')
title('Cordic & cos\theta')
legend('truth','cordic')
subplot(222),hold on
plot(theta,t_sin,'LineWidth',3,'Color','g')
plot(theta,sine,'k')
xlim([0 1.6]),hold off
xlabel('\theta'),ylabel('sin\theta')
title('Cordic & sin\theta')
legend('truth','cordic')
subplot(2,2,3:4),plot(theta,t_cos-cosine,'m')% difference
hold on,plot(theta,t_sin-sine,'c'),hold off
xlabel('\theta'),ylabel('\Delta\{cos\theta/sin\theta\}')
legend('\Delta\{cos(.)\}',...
'\Delta\{sin(.)\}')
title('error for CORDIC-sin\theta/cos\theta')
%% test abs/atan
%
y=cos(theta);
absolute=x_abs;% datas provided by VS
arctan=x_atan;
t_abs=ones(size(y));% true values
t_atan=atan(y);
figure(2)
subplot(221),hold on
plot(y,t_abs,'LineWidth',3,'Color','y')
plot(y,absolute),hold off
xlabel('y'),ylabel('sqrt(x^2+y^2)')
title('Cordic & abs(x+yi)')
legend('truth','cordic')
subplot(222),hold on
plot(y,t_atan,'LineWidth',3,'Color','g')
plot(y,arctan),hold off
xlabel('y'),ylabel('atan(.)')
title('Cordic & atany')
legend('truth','cordic')
subplot(2,2,3:4)
plot(y,t_abs-absolute,'m'),hold on
plot(y,t_atan-arctan,'c'),hold off
xlabel('y'),ylabel('\Delta')
legend('\Delta\{abs(.)\}',...
'\Delta\{atan(.)\}')
title('error for abs(.) and atan(.)')
%% test multiply
%
x=sin(theta);
t_mult=x.*y;
mult=x_mult;
figure(3)
subplot(211)
plot(theta,t_mult,'LineWidth',3,'Color','g')
hold on,plot(theta,mult),hold off
xlabel('\theta'),ylabel('sin\thetacos\theta')
title('Cordic & multiply')
legend('truth','cordic')
subplot(212),plot(theta,t_mult-mult,'c')
xlabel('\theta'),ylabel('\Delta\{xz\}')
title('error for multiply')
%% test devision
%
t_dev=y./x;
dev=x_dev;
figure(4)
subplot(221)
plot(theta,t_dev,'LineWidth',3,'Color','g')
hold on,plot(theta,dev,'k'),hold off
xlabel('\theta'),ylabel('cos\theta/sin\theta')
axis([0 .6 0 65]),title('Cordic ? devision')
legend('truth','cordic')
subplot(222)
plot(theta,t_dev,'LineWidth',3,'Color','g')
hold on,plot(theta,dev,'k'),hold off
xlabel('\theta'),ylabel('cos\theta/sin\theta')
xlim([.6 1.6]),title('Cordic ? devision')
legend('truth','cordic')
subplot(223),plot(theta,t_dev-dev,'c')
xlabel('\theta'),ylabel('\Delta')
xlim([0 .6]),title('error for devision')
subplot(224),plot(theta,t_dev-dev,'c')
xlabel('\theta'),ylabel('\Delta\{y/x\}')
xlim([.6 1.6]),title('error for devision')
% ATTENTION, when theta<0.3 the results overflows
%% test sinh/cosh
%
sinhyp=x_sinh;% datas provided by VS
coshyp=x_cosh;
t_cosh=cosh(theta);% true values
t_sinh=sinh(theta);
figure(4)
subplot(221),hold on % contrast diagram
plot(theta,t_cosh,'LineWidth',3,'Color','y')
plot(theta,coshyp,'b')
xlim([0 1.6]),hold off
xlabel('\theta'),ylabel('cosh\theta')
title('Cordic & cosh\theta')
legend('truth','cordic')
subplot(222),hold on
plot(theta,t_sinh,'LineWidth',3,'Color','g')
plot(theta,sinhyp,'k')
xlim([0 1.6]),hold off
xlabel('\theta'),ylabel('sinh\theta')
title('Cordic & sinh\theta')
legend('truth','cordic')
subplot(2,2,3),plot(theta,t_cosh-coshyp,'m')% difference
hold on,plot(theta,t_sinh-sinhyp,'c'),hold off
xlabel('\theta'),ylabel('\Delta\{sinh\theta/cosh\theta\}')
legend('\Delta\{cosh\theta\}','\Delta\{sinh\theta\}')
title('error for sinh(.)/cosh(.)'),xlim([0 1])
% ATTEMTION when theta within 1 of 1.5 sinh overflows
subplot(2,2,4),plot(theta,t_cosh-coshyp,'m')% difference
hold on,plot(theta,t_sinh-sinhyp,'c'),hold off
xlabel('\theta'),ylabel('\Delta\{sinh\theta/cosh\theta\}')
legend('\Delta\{cosh\theta\}','\Delta\{sinh\theta\}')
title('error for sinh(.)/cosh(.)')
xlim([1 1.6])% ATTENTION errors in different theta domain
%% test sqrt/atanh
%
alpha=linspace(.5,1,100)';
t_sqrt=sqrt(alpha);
squreroot=x_sqrt(:,1);
figure(5)
subplot(221),hold on
plot(alpha,t_sqrt,'LineWidth',3,'Color','y')
plot(alpha,squreroot),hold off
xlabel('\alpha'),ylabel('sqrt(\alpha)')
title('Cordic & sqrt(\alpha)')
legend('truth','cordic')
subplot(222)
plot(alpha,t_sqrt-squreroot,'c')
xlabel('\alpha'),ylabel('\Delta\{sqrt(\alpha)\}')
title('error for sqrt(.)')
%
gamma=linspace(.16,.76,100)';
t_atanh=atanh(gamma);
arctanh=x_atanh(:,1);
subplot(223),hold on
plot(gamma,t_atanh,'LineWidth',3,'Color','g')
plot(gamma,arctanh),hold off
xlabel('\gamma'),ylabel('atanh\gamma')
title('Cordic & atanh\gamma')
legend('truth','cordic')
subplot(2,2,4)
plot(thetah,t_atanh-arctanh,'m')
xlabel('\gamma'),ylabel('\Delta\{atanh\gamma\}')
title('error for atanh(.)')
##### SOURCE END #####--> </body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -