If z is a vector , what is the difference between angle(z) and atan2(z)

7 ビュー (過去 30 日間)
Hassan Abdelazeem
Hassan Abdelazeem 2022 年 1 月 12 日
コメント済み: Hassan Abdelazeem 2022 年 1 月 12 日
If z is a vector z=x+j*y, what is the difference between angle(z) and atan2(z)
becuae when I used angle(x+i*.y) gives a differen results
this is the matlab code
clc
clear
close all
f=50;w=2*pi*f;Tperiod=1/f;Tmax=4*Tperiod;Dt=Tperiod/(6*f);N=(Tmax/Dt)+1;
t0=0.00001;
t=zeros(N,1); Bmx=zeros(N,1); Bmy=zeros(N,1);
thetaB=90;Bmax=1.6;
for k=1:N+1
t(k)=t0+Dt*(k-1);
Bmx(k)=Bmax*sin(w*t(k));
Bmy(k)=Bmax*sin(w*t(k)-(thetaB)*pi/180);
end
z=Bmx+i*Bmy;
figure(1);
plot(z,'k*')
hold on
plot(Bmx,Bmy,'r','LineWidth',2)
figure(2)
P1 = atan2(Bmy,Bmx);
P2=1.6.*(180/pi).*angle(Bmx+i.*Bmy);
P3=1.6.*(180/pi).*angle(z);
hold on
plot(P1,'k*')
plot(P2,'r','LineWidth',2)
plot(P3,'b','LineWidth',2)
  1 件のコメント
John D'Errico
John D'Errico 2022 年 1 月 12 日
You could not possibly have used atan2, becuase atan2 does not work with only one argument.

サインインしてコメントする。

採用された回答

John D'Errico
John D'Errico 2022 年 1 月 12 日
編集済み: John D'Errico 2022 年 1 月 12 日
Perhaps you did not use atan2 properly. Consider this example:
z = [1+i,1-i,-1+i,-1-i];
angle(z)
ans = 1×4
0.7854 -0.7854 2.3562 -2.3562
atan2(imag(z),real(z))
ans = 1×4
0.7854 -0.7854 2.3562 -2.3562
If you want the result in degrees, this is not difficult. In fact, with atan2d, it already does the conversion for you to degrees.
angle(z)*180/pi
ans = 1×4
45 -45 135 -135
atan2d(imag(z),real(z))
ans = 1×4
45 -45 135 -135
The two functions will be compatible, as long as you use them properly. remember that atan2 is a TWO argument utility. You need to separate out the real and imaginary parts to use atan2 or atan2d.

その他の回答 (1 件)

Paul
Paul 2022 年 1 月 12 日
編集済み: Paul 2022 年 1 月 12 日
atan2() returns the answer in radians. So multiply it by 180/pi as for P2 and P3 (or use atan2d(), though atan2d() might result in small numerical differences). And P1 will also need to be multiplied by 1.6 to match P2 and P3.
  3 件のコメント
Paul
Paul 2022 年 1 月 12 日
Absolutely. Which is why, P1 needs to be include the 1.6*(*180/pi) factor as applied to P2 and P3.
Hassan Abdelazeem
Hassan Abdelazeem 2022 年 1 月 12 日
thank you for your answer
So, I can use these functions to determine the lag angle between the real and the imaginary part?

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by