plotting Intensity function which consists of an exponential sum

조회 수: 1 (최근 30일)
Elinor Ginzburg
Elinor Ginzburg 2020년 3월 25일
댓글: Sriram Tadavarty 2020년 3월 26일
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
Elinor Ginzburg
Elinor Ginzburg 2020년 3월 26일
thank you for your reply, but it still doesn't work. perhaps you have another idea? now it looks like this:
%% Question 03 %%
% param defenition %
L=100; N=20; d=1; k=10; Ar=1;
A=0.1;
theta=linspace(-pi/2,pi/2,200);
epsilon=rand(0,1);
phase=(d+A*epsilon)*sin(theta);
psi=1;
for n=1:N
psi=psi+(exp(i*k*phase).^n);
end
I=((abs(psi)).^2);
plot(I)
Sriram Tadavarty
Sriram Tadavarty 2020년 3월 26일
rand(0,1) returns empty vector. So instead provide rand(1,1)

댓글을 달려면 로그인하십시오.

답변 (1개)

Birdman
Birdman 2020년 3월 26일
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
Elinor Ginzburg
Elinor Ginzburg 2020년 3월 26일
it worked! thank you so much! I had no idea I need to use rand instead of rand(0,1). how can you keep track between all the changes in different versions? thanks once again!
Birdman
Birdman 2020년 3월 26일
I pay attention to details :) you are welcome.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Graphics Performance에 대해 자세히 알아보기

제품


릴리스

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by