1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127
|
import matplotlib from math import factorial from numpy import * from pylab import * from numpy.polynomial.hermite import *
matplotlib.rc('font', family='serif') matplotlib.rc('font', size=16) matplotlib.rc('legend', fontsize=16) matplotlib.rc('legend', numpoints=1) matplotlib.rc('legend', handlelength=1.5) matplotlib.rc('legend', frameon=False) matplotlib.rc('xtick.major', pad=7) matplotlib.rc('xtick.minor', pad=7) matplotlib.rc('lines', lw=1.5) matplotlib.rc('text', usetex=True) matplotlib.rc('text.latex', preamble=[r'\usepackage[T1]{fontenc}', r'\usepackage{amsmath}', r'\usepackage{txfonts}', r'\usepackage{textcomp}']) close('all') figure(figsize=(6, 4.5)) c=137.0359998 N=1024+512
def H(Psi, x, t, dt): Psi=reshape(Psi, (N, 2)) dx=x[1]-x[0] Psi_new=empty_like(Psi) Psi_new[1:-1, 0]=-1j*c*(Psi[2:, 1]-Psi[0:-2, 1])/(2*dx) + c**2*Psi[1:-1, 0] Psi_new[1:-1, 1]=-1j*c*(Psi[2:, 0]-Psi[0:-2, 0])/(2*dx) - c**2*Psi[1:-1, 1] Psi_new[0, 0]=Psi_new[0, 1]=0 Psi_new[-1, 0]=Psi_new[-1, 1]=0 Psi_new*=dt return reshape(Psi_new, 2*N)
def Lanczos(Psi, x, t, dt, H, m): Psi_=Psi.copy() V_j, V_j_1=[], [] A=zeros((m, m)) norms=zeros(m) for j in range(0, m): norms[j]=norm(Psi_) V_j=Psi_/norms[j] Psi_=H(V_j, x, t, dt) if j>0: A[j-1, j]=A[j, j-1]=vdot(V_j_1, Psi_).real Psi_-=A[j-1, j]*V_j_1 A[j, j]=vdot(V_j, Psi_).real Psi_-=A[j, j]*V_j V_j_1, V_j=V_j, V_j_1 l, v=eig(A) c=dot(v, dot(diag(exp(-1j*l)), v[0, :]*norms[0])) Psi_, Psi=Psi, zeros_like(Psi) for j in range(0, m): V_j=Psi_/norms[j] Psi+=c[j]*V_j Psi_=H(V_j, x, t, dt) if j>0: A[j-1, j]=A[j, j-1]=vdot(V_j_1, Psi_).real Psi_-=A[j-1, j]*V_j_1 A[j, j]=vdot(V_j, Psi_).real Psi_-=A[j, j]*V_j V_j_1, V_j=V_j, V_j_1 return Psi
x0, x1=-0.5, 0.5 x=linspace(x0, x1, N) dx=x[1]-x[0] dt=4./c**2
dp=2*pi/(N*dx) p=(arange(0, N)-0.5*(N-1))*dp
p_mu=75. sigma_p=50. x_mu=-0.05
d_p=sqrt(0.5+0.5/sqrt(1+p**2/c**2)) d_m=sqrt(0.5-0.5/sqrt(1+p**2/c**2)) d_m[p<0]*=-1
rho=(2*pi*sigma_p**2)**(-0.25)*exp(-(p-p_mu)**2/(4*sigma_p**2) - 1j*p*x_mu) Psi=zeros((N, 2), dtype='complex') Psi[:, 0]=d_p*rho Psi[:, 1]=d_m*rho
Psi[:, 0]*=exp(1j*x[0]*dp*arange(0, N)) Psi[:, 1]*=exp(1j*x[0]*dp*arange(0, N)) Psi=ifft(Psi, axis=0) Psi[:, 0]*=dp*N/sqrt(2*pi)*exp(1j*x*p[0]) Psi[:, 1]*=dp*N/sqrt(2*pi)*exp(1j*x*p[0])
for k in range(0, 20): clf() plot(x, Psi[:, 0].real**2+Psi[:, 0].imag**2+ Psi[:, 1].real**2+Psi[:, 1].imag**2, color='#266bbd', label=r'$|\Psi(x)|^2$') gca().set_xlim(x0, x1) gca().set_ylim(-1, 16) xlabel(r'$x$') legend(loc='upper left') tight_layout() draw() show() pause(0.05) Psi=reshape(Lanczos(reshape(Psi, 2*N), x, 0, dt, H, 128), (N, 2))
|