function psi = packetfunc(v,t) % Plots Gaussian wavepacket for given velocity and time. % packetfunc(v,t) returns a complex vector with a Gaussian % wavepacket with velocity v, time t, and position in % the interval x = -10:0.01:10. v, x, and t are dimensionless % as described in the notes. The magnitude squared of the % wave function is plotted as well as its real and imaginary % parts. % v = 0; % dimensionless velocity % t = 0; % dimensionless time x = -10:0.01:10; % dimensionless position and sets range psi = exp(i*v*(x - 0.5*v*t)); psi = psi.*exp(-0.25*((x - v*t).^2)/(1 + 0.5*i*t)); psi = psi./sqrt(1 + 0.5*i*t)/((2*pi)^0.25); % The convention in Matlab is to have the real part of sqrt() > 0. plot(x,abs(psi).^2,x,real(psi),x,imag(psi)) xlabel('x') legend('|psi |^2','real(psi)','imag(psi)')