Range Theta from 0 to 2Pi and plot

49 次查看(过去 30 天)
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')

采纳的回答

Les Beckham
Les Beckham 2016-9-9
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 个评论
james hayek
james hayek 2016-9-10
This community is amazing, thanks for all the help!! Everything works as expected, thanks again,

请先登录,再进行评论。

更多回答(1 个)

KSSV
KSSV 2016-9-9
You may consider using
theta = linspace(0,2*pi,N) ; % where N is number of points you want.
  1 个评论
james hayek
james hayek 2016-9-9
编辑:james hayek 2016-9-9
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?

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Annotations 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by