Document 10390175

advertisement
5
4
|psi|2
3
2
1
0
0
0.2
0.4
0.6
x
0.8
1
Problem 2c m-file
nterms = 100;
n = 1:nterms;
c = sqrt(2)*(sin((n-2)*pi/2)./(pi*(n-2)) - sin((n+2)*pi/2)./(pi*(n+2)));
c(2) = sqrt(2)/2; % special case from notes
x = 0:0.001:1;
psi = 0*x;
for counter = 1:nterms,
psi = psi + c(counter)*sqrt(2)*sin(pi*counter*x);
end
exactpsi = 2*sin(2*pi*x).*(x < 0.5);
plot(x,abs(psi).^2,x,abs(exactpsi).^2)
xlabel(’x’)
ylabel(’|psi|^2’)
Problem 2d m-file
% Here we start with the wave function of leftside.m (constant for x < 0.5
% and zero otherwise and then time evolve by including the proper phase
% factors. At each step in time |psi|^2 is plotted.
nterms = 4; % Number of terms kept in the series.
n = 1:nterms;
n = 1:nterms;
c = sqrt(2)*(sin((n-2)*pi/2)./(pi*(n-2)) - sin((n+2)*pi/2)./(pi*(n+2)));
c(2) = sqrt(2)/2; % special case from notes
x = 0:0.001:1;
tmax = 2*pi; % This is the maximum time kept because after this the
% wave function repeats.
ntime = 100; % number of time steps
for tcounter = 0:ntime,
t = tcounter*tmax/ntime;
psi = 0*x;
for counter = 1:nterms,
psi = psi + c(counter)*sqrt(2)*sin(pi*counter*x)*exp(-i*counter^2 * t);
end
plot(x,abs(psi).^2)
xlabel(’x’)
ylabel(’|psi|^2’)
pause(0.5);
end
Download