In [13]:
import numpy as np
import matplotlib.pyplot as plt
from numpy import linalg as LA
%matplotlib inline
In [14]:
def V(x, w=.0001, l=10., V_0=200.):
return -V_0 / 2. * (np.tanh((x + l / 2) / w) \
- np.tanh((x - l / 2) / w)) + V_0
In [15]:
x = np.linspace(-20, 20, 1000)
for k in - np.arange(-1, 2):
plt.plot(x, V(x, 10. ** k, 10, 10),\
label='w = 10^'+str(k))
plt.legend()
plt.figure()
for k in np.arange(1, 10, 3):
plt.plot(x, V(x, 1, 10, k),\
label='V_0 = '+str(k))
plt.legend()
plt.figure()
for k in np.arange(1, 10, 3):
plt.plot(x, V(x, 1, k, 4),\
label='l = '+str(k))
plt.legend()
Out[15]:
In [16]:
# define the grid
N = 2 ** 10 # number of grid points
x0 , x1 = -20. , 20. # grid boundaries
dx =(x1 - x0) / (N -1) # grid spacing
x = np.linspace (x0 , x1 , N) # grid points
# setup the Hamiltonian matrix
H = -1 / (2 * dx ** 2) * (np.diag(np.ones(N - 1) , -1) - 2 * np.diag(np.ones(N)) + \
np.diag(np.ones(N - 1), 1)) + np.diag(V(x))
# compute eigenvalues
E = LA.eigvalsh(H)
# plot first eigenvalues
n =100
ns = np.array (range (0 , n ))
plt.plot( ns, np.sort (E)[0: n ] ,'+', label ='eigenvalues of discretized Hamiltonian ')
plt.plot(ns[E_teo(ns) < 200], E_teo(ns)[E_teo(ns) < 200])
plt.grid()
sum(E < 200)
Out[16]:
In [17]:
E , Psi_E = LA.eigh(H)
Psi_E /= np.sqrt (dx)
for n in np.arange(2):
c = np.zeros ( n +1)
c [n]=1
plt.plot (x ,- Psi_E [: , n ] , label ='$n =% i$ ' % n )
plt.legend()
def E_teo(n):
return n** 2 * np.pi ** 2 / (2 * (10**2))
print (E[:5])
print (E_teo(np.arange(5))/78)
In [18]:
plt.plot(x, V(x))
Out[18]:
In [30]:
c=137.0359998
N = 2 ** 9 # number of grid points
x0 , x1 = -20. , 20. # grid boundaries
dx =(x1 - x0)/(N -1) # grid spacing
x = np.linspace (x0 , x1 , N) # grid points
# setup the Hamiltonian matrix
sigma_1=np.array([[0, 1], [1, 0]])
sigma_3=np.array([[1, 0], [0, -1]])
p=np.diag(-np.ones(N-1), -1) + np.diag(np.ones(N-1), +1)
p[0, N-1]=-1
p[N-1, 0]=1
p/=2*dx
H_free=c*(-1j)*np.kron(p, sigma_1) + np.kron(np.eye(N), sigma_3*c**2)
H=H_free+np.kron(np.diag(V(x)), np.eye(2))
# compute eigenvalues
E = LA.eigvalsh(H)
# plot first eigenvalues
n =100
ns = np.array (range (0 , n ))
plt.plot( ns, E[:n] ,'+', label ='eigenvalues of discretized Hamiltonian ')
#plt.plot(ns[E_teo(ns) < 200], E_teo(ns)[E_teo(ns) < 200])
plt.grid()
sum(E < 200)
Out[30]:
In [31]:
E
Out[31]:
In [21]:
E , Psi_E = LA.eigh(H)
Psi_E /= np.sqrt (dx)
for n in np.arange(2):
c = np.zeros ( n +1)
c [n]=1
plt.plot (x ,- Psi_E [: , n ] , label ='$n =% i$ ' % n )
In [ ]:
In [ ]:
In [ ]:
In [36]:
from pylab import *
close('all')
def V(x, V0, l, w):
return V0/2*(tanh((x+l/2)/w) - tanh((x-l/2)/w))
c=137.0359998 # speed of light
# define the grid
N=512 # number of grid points
x0, x1=-0.5, 0.5 # grid boundaries
dx=(x1-x0)/(N-1) # grid spacing
x=linspace(x0, x1, N) # grid points
l=3.2/c
w=0.3/c
# setup the Hamiltonian matrix
sigma_1=array([[0, 1], [1, 0]])
sigma_3=array([[1, 0], [0, -1]])
p=diag(-ones(N-1), -1) + diag(ones(N-1), +1)
p[0, N-1]=-1
p[N-1, 0]=1
p/=2*dx
H_free=c*(-1j)*kron(p, sigma_1) + kron(eye(N), sigma_3*c**2)
H=H_free+kron(diag(V(x, -1000, l, w)), eye(2))
E=eigvalsh(H)
plt.plot(E)
xlabel('$V_0/(m_0c^2)$')
ylabel('$E/(m_0c^2)$')
gca().set_yticks(arange(-8, 4))
tight_layout()
show()
In [ ]:
In [ ]: