Complex number and degrees

조회 수: 10 (최근 30일)
john
john 2013년 2월 18일
Hi,
result of code
x=3*cos(pi)+3*sin(pi)*i
is -3.0000 0.0000i.
But result of this code
x=3*cosd(180)+3*sind(180)*i
is -3.
Why result of second code is not in form -3.0000 0.0000i.???
How can I do this without transformation from deg to rad???
Thank you
x=3*cos(pi)+3*sin(pi)*
  댓글 수: 1
Matt Kindig
Matt Kindig 2013년 2월 18일
편집: Matt Kindig 2013년 2월 18일
In short, numerical precision. In the first case, MATLAB represents sin(pi) as 3.6739e-16 (on my x64 machine), while in the second case, sind(180) is identically zero. Both are equivalent.

댓글을 달려면 로그인하십시오.

채택된 답변

Azzi Abdelmalek
Azzi Abdelmalek 2013년 2월 18일
편집: Azzi Abdelmalek 2013년 2월 18일
Because of precision problem with pi
sin(pi)=1.2246e-16
and
sind(180)=0

추가 답변 (1개)

Youssef  Khmou
Youssef Khmou 2013년 2월 18일
편집: Youssef Khmou 2013년 2월 18일
hi Jhon,
i can not say why using cosd and sind gives only double not complex, but you can use exponential representation which is commonly used in Elec,Eng :
R= Magnitude * exp(j* Angle ) in radian
r=3*exp(j*pi)
  댓글 수: 1
Youssef  Khmou
Youssef Khmou 2013년 2월 18일
ok then its about precision

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Dates and Time에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by