In [1]:
import numpy as np
import matplotlib.pyplot as plt
from numpy import linalg as LA
%matplotlib inline
In [21]:
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 [22]:
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[22]:
In [17]:
# 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[17]:
In [20]:
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 [23]:
plt.plot(x, V(x))
Out[23]:
In [ ]: