Range Theta from 0 to 2Pi and plot
80 views (last 30 days)
Show older comments
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')
0 Comments
Accepted Answer
Les Beckham
on 9 Sep 2016
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.
More Answers (1)
KSSV
on 9 Sep 2016
You may consider using
theta = linspace(0,2*pi,N) ; % where N is number of points you want.
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!