Reputation:
I was trying in one hour to plot a graph in matlab but got stuck in the following :
n1=1; %konstant
n2=1.5; %konstant
theta1=0:90; % I define my degree values from 0 to 90
theta2=asind(n1*sind(theta1))/n2; % Snell's law : I calculate the other angle values which are depending on the values of the theta1
% NOW I WANT TO CALCULATE THE Rparallell VALUES WHICH ARE DEPENDING ON TWO INPUTS(theta1 and theta2)
%Here is my first attempt to calculate the Rparallell : it does not work
%because the size of Rparallell is 1 by 1
for i=1:length(theta1)
for k=1:length(theta2)
Rparallell=(((n2*cosd(theta1)-(n1*cosd(theta2))))/((n2*cosd(theta1))+(n1*cosd(theta2)))).^2;
end
end
%Here is my second attempt to calculate the Rparallell : it does not work
%because the size of Rparallell is 1 by 1
for i=1:91
Rparallell=(((n2*cosd(theta1(:,i))-(n1*cosd(theta2(:,i)))))/((n2*cosd(theta1(:,i)))+(n1*cosd(theta2(:,i))))).^2;
end
When I execute the code I get Rparallell as a 1 by 1 vector but that is not what I want .. I want Rparallell become a vector of 1 by 91 values ..
I even tried to insert Rparallell=zeros(1,91)
but it did not help to make the Rparallell a vector of 1 by 91 values ..
I want to calculate the Rparallell value when the value of theta1 and its corresponding value of theta2 are calculated ..
How to correct the code so that Rparallell become a vector of 1 by 91 values ?
thank you very much
Upvotes: 1
Views: 129
Reputation:
This should help you
Rparallell=zeros(1,91)
for i=1:91
Rparallell(i)=(((n2*cosd(theta1(:,i))-(n1*cosd(theta2(:,i)))))/((n2*cosd(theta1(:,i)))+(n1*cosd(theta2(:,i))))).^2;
end
Rparallell(i)
accesses the i-th element of Rparallell
, so every value is stored in a different element of this vector.
Upvotes: 2