% Matlab file to produce movies of time evolution for problems 2.a. and b. % in homework assignment 5. npts = 500; % The actual number of points in one more than this. nterms = 20; x = (0:npts)/npts; n = (1:nterms)'; ratioenergies = (n.*n)'; angle = pi*n*x; basis = sqrt(2)*sin(angle); coefstep = 2*(1 - cos(pi*(n')/2))./(pi*(n')); figure(1) time = 0:0.001:1; for counter = 1:length(time), coefstepn = coefstep.*exp(-i*ratioenergies*2*pi*time(counter)); psin = coefstepn*basis; plot(x,abs(psin).^2) axis([0 1 0 5]) title('Homework 5, Problem 2.a.') pause(0.1) end figure(2) time = 0:0.01:1; for counter = 1:length(time), densn = 0.5*(basis(1,:).^2 + basis(2,:).^2 + 2*cos(2*pi*time(counter))*basis(1,:).*basis(2,:)); plot(x,densn) axis([0 1 0 5]) title('Homework 5, Problem 2.b.') pause(0.1) end