Reputation: 1
I am trying to plot Reflection coefficient by using this formula:
Code:
E1=1;
E2=2.32*E1;
for tetai=1:90
numerator=cos(tetai)-(sqrt(E2/E1).*sqrt(1-(E1/E2).*sin(tetai)^2));
denominator=cos(tetai)+(sqrt(E2/E1).*sqrt(1-(E1/E2).*sin(tetai)^2));
eta=numerator/denominator;
plot(tetai,eta,'r');
hold on
end
title('Plots')
xlabel('\Theta')
ylabel('\Gamma')
After repeating E2 values with 2.56, 4, 9, 16, 25, and 81 I should obtain the following result (At first step I just wanted to obtain a single value with E2=2.32):
But unfortunately, there is no graphics on the plot result screen. So, what is the mistake?
Note: I use MATLAB R2015a
Upvotes: 0
Views: 1392
Reputation: 19689
Mistakes:
You're using sin
and cos
and inputting angle in degrees. Either convert the angle or even better use the functions dedicated for this purpose. i.e sind
and cosd
respectively.
You don't see anything in output because you're plotting point by point. For that, some marker should've been specified. But anyway, what you want to plot is not this. You want to plot a line instead.
Another problem in using plot
is that you are not plotting what you think you should be plotting. The image that you showed in the question is a plot between |Γᵇ⊥| and θᵢ , not Γᵇ⊥ and θᵢ
Fixed code:
E1=1;
E2i=[2.32, 2.56, 4, 9, 16, 25, 81];
gamma = zeros(1,91); %Pre-allocation
for k=1:7
E2 = E2i(k);
for theta_i=0:90
numerator=cosd(theta_i)- sqrt((E2/E1)*(1-(E1/E2)*sind(theta_i)^2));
denominator=cosd(theta_i)+ sqrt((E2/E1)*(1-(E1/E2)*sind(theta_i)^2));
gamma(theta_i+1)=numerator/denominator;
end
plot(0:90,abs(gamma));
hold on;
text(45,abs(gamma(45)),['\epsilon_2/\epsilon_1 = ',num2str(E2/E1)]);
end
title('Plots'); xlabel('\theta_i (degrees)'); ylabel('|\Gamma^b_\perp|');
Output:
Upvotes: 10
Reputation: 965
You can try create a nan vector outside the loop, fill the vector in the iterations, and plot outside the loop.
E1=1;
E2=2.32*E1;
Data=nan(90);
for tetai=1:90
numerator=cos(tetai)-(sqrt(E2/E1).*sqrt(1-(E1/E2).*sin(tetai)^2));
denominator=cos(tetai)+(sqrt(E2/E1).*sqrt(1-(E1/E2).*sin(tetai)^2));
eta=numerator/denominator;
Data(tetai)=eta;
end
plot(Data, 'r');
title('Plots')
xlabel('\Theta')
ylabel('\Gamma')
Edited on phone, not tested.
Upvotes: 1