フィルターのクリア

plotting using if and for loop

1 回表示 (過去 30 日間)
mhya k
mhya k 2022 年 6 月 13 日
編集済み: mhya k 2022 年 6 月 13 日
Hello,
I should programming this formula and plot the picture (pic1) in below with these condiction (pic2) but when I run my code it didn't give me any curve and since I didn't get any I only write first formula in here.
it would be great if someone can help me.
my code ;
close all;
clc;
clear all;
x=0:0.01:pi/2;
n2=1.5;
n1=1;
n=n1/n2;
C = asin(n);
P = atan(n);
B= sqrt((sin(x)^2 - (n^2));
D = (n^2)*cos(x);
y1=180;
y2=0;
y3= 2*atan(B/D);
z=zeros(1,length(x));
for j=1:length(x);
if (x(j) < C);
z(j)=y1(j);
elseif (x(j)>C) && (x(j)<P);
z(j)=y2(j);
else
z(j)=y3(j);
end
end
i=x*180/pi;
plot(i,z)

採用された回答

Ganesh
Ganesh 2022 年 6 月 13 日
The issue seems to be 3 things.
a) The elements aren't dot squared(line 10)
b) y1, and y2 are integers but are indexed(only arrays and other such data types can be indexed)
c) Inconsistency between radians and degrees(z hasnt been converted to degrees)
The below code fixes the issues in order to plot Theta(tm).
close all;
clc;
clear all;
x=0:0.01:pi/2;
n2=1.5;
n1=1;
n=n1/n2;
C=asin(n);
P=atan(n);
B=sqrt(sin(x).^2 - (n^2));
D=(n^2)*cos(x);
y1=pi;
y2=0;
z=zeros(1,length(x));
for j=1:length(x);
if (x(j) < P);
z(j)=y1;
elseif (x(j)>P) && (x(j)<C);
z(j)=y2;
else
z(j)=2*atan(real(B(j)/D(j)));
end
end
i=x*180/pi;
z=z*180/pi;
plot(i,z)
  1 件のコメント
mhya k
mhya k 2022 年 6 月 13 日
編集済み: mhya k 2022 年 6 月 13 日
omg thank you it worked. really thank for your help.

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

その他の回答 (0 件)

カテゴリ

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

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by