% % Particle in a box simulator: given an initial psi(x,0)=psi0, it % evolves it in time and for each time slice plots Real psi(x,t), Imag, % and |Psi|^2. We plot quantities in terms of scaled variables (e.g. x/a). % % The box is 0nmax)=0. % The higher nmax, the higher the fidelity of the calculation. E(:) % contains the energies of the states En nmax=100; E = E1*[1:nmax].^2; E = E'; % Here we create the x axis by making a uniform grid of x values from 0 % to a with nx points. We then get spacing and use the formula % for the eigenstates. psin holds the eigenstates as a matrix: the columns % are indexing the states n and the rows are the x values. nx=100; x=linspace(0,a,nx)'; dx=x(2)-x(1); nvec=[1:nmax]'; psin = sqrt(2/a)*sin(pi*x*nvec'/a); % a small width sig = a/10; % Some choices of intitial wave functions %(1) A Gaussign packet centered in mix box with width sig and momentum % 50*hbar/a. %%psi0 = exp(-(x-a/2).^2/sig^2).*exp(i*50/a*x); % (2) A "square" intial state centered at mid box and basically non-zero % between |x-a/2|