Range Theta from 0 to 2Pi and plot

Hello everybody,
I'm am looking to make a plot of numerous perpendicular components of a Transverse Electric Field. I did the general work on paper and come up with the following:
I wrote the following script in which I thought would range theata_i from 0 to Pi/2 I received help from Dr. Siva as commented below.
Using the suggestion I was able to see a range of values for both theata_i as well as theata_t
However, I do not see a range of values for the reflectedPerpendic variable. I would like to plot this range of values VS theata_i or theata_t but can not since only one value is being assigned to the variable "reflectedPerpendic"
How can I write this to an array? I tried adding brackets. I also tried appending a (i) to the variable as such: reflectedPerpendic(i) to add it to an array element, but that didn't work.
Maybe I have to use a for loop, if so, I am not sure of the approach to take.
The code is as follows:
% James Hayek
%
% Setting up the variables for the parameters
n1 = 1;
n2 = 1.5;
% We are looking to range theata_i from 0 t 90 degrees
% For now, we will use a constant value and then range as we finialize the
% script
theata_i = linspace(0,pi/2,50)
% The value of theata_t as per Snells Law
theata_t = asin((n1/n2)*(sin(theata_i)))
% The function as derived from HW1 ii section a
reflectedPerpendic = (n1*cos(theata_i) - n2*cos(theata_t))/(n1*cos(theata_i) + n2*cos(theata_t))
% Using the plot function
plot(abs(theata_t), abs(reflectedPerpendic),'x')

 Accepted Answer

Change the divide in your equation for reflectedPerpendic to an element-by-element divide as follows:
reflectedPerpendic = (n1*cos(theata_i) - n2*cos(theata_t))./(n1*cos(theata_i) + n2*cos(theata_t))
Note the use of './' instead of '/'. Without the '.' you are doing a vector divide, the result of which is a scalar.

1 Comment

This community is amazing, thanks for all the help!! Everything works as expected, thanks again,

Sign in to comment.

More Answers (1)

KSSV
KSSV on 9 Sep 2016
You may consider using
theta = linspace(0,2*pi,N) ; % where N is number of points you want.

1 Comment

james hayek
james hayek on 9 Sep 2016
Edited: james hayek on 9 Sep 2016
Thanks, that worked quite well. But looks like I have another problem:
In terms of the "reflectedPerpendic" variable, This only places one value into the variable reflectedPerpendic I would love to find a way to write all elements to an array and plot each of those values found. Brackets didn't work, and I couldn't think of how using a FOR loop. With that aside, I didn't need a for loop for the variables theata_i and theata_t
How come I don't see a range of values for "reflectedPerpendic"?
Any ideas?

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!