Error in plotting function of atand against different values of angle

1 回表示 (過去 30 日間)
Muhammad Rehan
Muhammad Rehan 2013 年 10 月 7 日
コメント済み: Muhammad Rehan 2013 年 10 月 8 日
Hi All, I am getting error Error using atand Argument should be real while executing below code. Kindly help to correct it.
n1=1.51;
n2=1;
anglec = asind (n2/n1);
angleTE=[];
angleTM=[];
for angle= 1:20:90
angleTE(angle)= 2*atand((sqrt (((sind (angle))^2) - ((sind (anglec))^2))) / (cosd (angle)));
angleTM(angle) = 2*atand( (sqrt (((sind(angle))^2) - ((sind (anglec))^2))) / ((cosd (angle))*(sind(anglec))^2));
end
plot(angle,angleTE)
plot(angle,angleTM)

回答 (1 件)

Walter Roberson
Walter Roberson 2013 年 10 月 7 日
When angle < anglec then sind(angle)^2 < sind(anglec)^2 so subtracting the two gives a negative and sqrt() of a negative is imaginary.
Side note: as both expressions have (sqrt (((sind (angle))^2) - ((sind (anglec))^2))) in the numerator, calculate that once per loop iteration and then the two angle calculations simplify.
You should be considering whether you should use atan2() and then converting the radian answer to degrees.
  5 件のコメント
Walter Roberson
Walter Roberson 2013 年 10 月 8 日
Is there perhaps something in the phrasing of the question to indicate that theta1 must be greater than thetac ? Because the expression in the sqrt() can definitely end up negative.
Muhammad Rehan
Muhammad Rehan 2013 年 10 月 8 日
編集済み: Muhammad Rehan 2013 年 10 月 8 日
yes you are right i have modified the code but now getting error in plot command.
Error using plot Vectors must be the same lengths.
n1=1.51;
n2=1;
anglec = asind (n2/n1);
angle= 42:1:90;
for ii = 42:1:90
angleTE(ii)= 2*atand((sqrt (((sind (ii))^2) - ((sind (anglec))^2))) / (cosd (ii)));
angleTM(ii) = 2*atand( (sqrt (((sind(ii))^2) - ((sind (anglec))^2))) / ((cosd (ii))*(sind(anglec))^2));
end
plot(angle,angleTE)

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

カテゴリ

Help Center および File ExchangeStartup and Shutdown についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by