% 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; c = (1 - cos(pi*0.5*n))*2./(pi*n); 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