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:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/156234/image.jpeg)
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
채택된 답변
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개)
KSSV
2016년 9월 9일
You may consider using
theta = linspace(0,2*pi,N) ; % where N is number of points you want.
참고 항목
카테고리
Help Center 및 File Exchange에서 Annotations에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!