plotting Intensity function which consists of an exponential sum
Show older comments
hello,
Im trying to plot the followin function in matlab:
where k=10,d=1,A=1,0.1,0.01, epsilon is a random number between [0,1], the summation n is from 1 to 20 and theta goes from [-pi/2,pi/2]
I've written this code:
% param defenition %
L=100; N=20; d=1; k=10; Ar=1;
A=0.1;
theta=linspace(-pi/2,pi/2,200);
phase=(d+A*epsilon)*sin(theta);
epsilon=rand(0,1);
function psi = Psi(x)
psi=1;
for n=1:N
psi=psi+(exp(i*k*phase).^n);
end
end
I=([abs(psi)].^2);
fplot(I,[-pi/2,pi/2])
but when I try to run it, I get nothing printed in the figure. what did I do wrong?
Thank you very much for your time and attention.
3 Comments
Sriram Tadavarty
on 25 Mar 2020
Remove function declaration and corresponding end, then replace fplot with plot(I)
Elinor Ginzburg
on 26 Mar 2020
Sriram Tadavarty
on 26 Mar 2020
rand(0,1) returns empty vector. So instead provide rand(1,1)
Answers (1)
Birdman
on 26 Mar 2020
Try this:
L=100; N=20; d=1; k=10; Ar=1;
A=0.1;
theta=linspace(-pi/2,pi/2,200);
epsilon=rand;
phase=(d+A*epsilon)*sin(theta);
psi=1;
for n=1:N
psi=psi+(exp(1i*k*phase).^n);
end
I=((abs(psi)).^2);
plot(I)
2 Comments
Elinor Ginzburg
on 26 Mar 2020
Birdman
on 26 Mar 2020
I pay attention to details :) you are welcome.
Categories
Find more on Annotations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!