필터 지우기
필터 지우기

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 CenterFile Exchange에서 Graphics Performance에 대해 자세히 알아보기

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by