function wave_packet3 % Figure 4.13 display('A wavepacket and the envelope') display('Run code three times with t - 0, 1, and 2') t = input('Please enter a value for t (0, 1 and then 2):') k=10; sig=1; kssq=(k*sig)^2; rt4pi=sqrt(sqrt(pi)); fac=2*sig^2; x=[-5:.01:30]; tc1=complex(1,t); tc2=complex(0,k*x-kssq*t/2); arg =-x.^2/(2*sig^2) +tc2; exp1=exp(arg/tc1); norm=1/(rt4pi*sqrt(sig)*tc1); psi=norm*exp1; wp=real(psi); dens=real(psi).^2+imag(psi).^2; subplot(2,1,1) plot(x,wp,'-k','linewidth',1.6) hold on xlabel('${x}$','Interpreter','latex','fontsize',36) ylabel('${\rm Real}[\psi(x,t)] $','Interpreter','latex','fontsize',32) axis([-5 30 -.8 .8]) set(gca,'FontSize',36) set(gca,'Ytick',[-.8:.4:.8],'linewidth',1.6) set(gca,'Xtick',[-5:5:30],'linewidth',1.6) str={'(A)'}; text(28,.65,str,'Interpreter','latex','fontsize',36) subplot(2,1,2) dens=real(psi).^2+imag(psi).^2; plot(x,dens,'-k','linewidth',1.6) xlabel('${x}$','Interpreter','latex','fontsize',36) ylabel('$|\psi(x,t)|^2$','Interpreter','latex','fontsize',36) axis([-5 30 0 .6]) set(gca,'FontSize',36) set(gca,'Ytick',[0:.2:.6],'linewidth',1.6) set(gca,'Xtick',[-5:5:30],'linewidth',1.6) str={'(B)'}; text(28,.5,str,'Interpreter','latex','fontsize',36) hold on