In [1]:
# ELECTRON IN CUBE - calculation of possible electron energies
# * EM-lectures: full justification of the equation + detailed comments
# * here: calculation of electron energies by means of Python/Sympy
#   1) we take Schrodinger equation for eln-in-cube: Ham[F(x,y,z)] = E * F(x,y,z)
#   2) we insert our previously derived solution F(x,y,z) into equation from (1)
#   3) we solve the equation for E which...
#      ...gives us the possible energies of electron in cube
#      ...confirms our solution F(x,y,z),
#         because the equation Hamiltonian[F(x,y,x)] = E*F(x,y,z) holds,
#         i.e. Hamiltonian[F(x,y,z)] gives const*F(x,y,z), where const=E
In [2]:
# (0) Initialize sympy
In [3]:
import sympy as sp
In [4]:
sp.init_printing()
In [5]:
# Prepare symbols for all future calculations
# (additional information, such as [real=True] is very useful
# (it should be inserted wherever possible - it can simplify solution significangly
(x,y,z)    = sp.symbols('x y z', real=True)
(Nx,Ny,Nz) = sp.symbols('N_x N_y N_z', integer=True, postitive=True)
(A,L)      = sp.symbols('A L', real=True, positive=True)
(E,m,h)    = sp.symbols('E m_e h', real=True, positive=True)
In [6]:
# (1) Define our solution of Schrodinger equation
# (the solution has been derived in EM lectures
In [7]:
from sympy import pi,cos
In [8]:
# Define partial solutions (separate solutions for x,y,z)
def F1(x): return ( A*cos(pi*Nx*x/L) )
def F2(y): return ( A*cos(pi*Ny*y/L) )
def F3(z): return ( A*cos(pi*Nz*z/L) )
In [9]:
# Define complete solution f(x,y,z) = f1(x)*f2(y)*f3(z)
def F(x,y,z): return ( F1(x)*F2(y)*F3(z) )
In [10]:
# Display our complete solution
# (reminder: the solution was derived in EM lectures
# (here we have just defined the solution in the form of function suitable for SymPy
F(x,y,z)
Out[10]:
$\displaystyle A^{3} \cos{\left(\frac{\pi N_{x} x}{L} \right)} \cos{\left(\frac{\pi N_{y} y}{L} \right)} \cos{\left(\frac{\pi N_{z} z}{L} \right)}$
In [11]:
# (2) Define and display left-hand-side = LHS of Schrodinger equation
In [12]:
Schr_LHS = -h**2/(2*m) * (sp.diff(F(x,y,z),x,2) + sp.diff(F(x,y,z),y,2) + sp.diff(F(x,y,z),z,2))
In [13]:
Schr_LHS
Out[13]:
$\displaystyle - \frac{h^{2} \left(- \frac{\pi^{2} A^{3} N_{x}^{2} \cos{\left(\frac{\pi N_{x} x}{L} \right)} \cos{\left(\frac{\pi N_{y} y}{L} \right)} \cos{\left(\frac{\pi N_{z} z}{L} \right)}}{L^{2}} - \frac{\pi^{2} A^{3} N_{y}^{2} \cos{\left(\frac{\pi N_{x} x}{L} \right)} \cos{\left(\frac{\pi N_{y} y}{L} \right)} \cos{\left(\frac{\pi N_{z} z}{L} \right)}}{L^{2}} - \frac{\pi^{2} A^{3} N_{z}^{2} \cos{\left(\frac{\pi N_{x} x}{L} \right)} \cos{\left(\frac{\pi N_{y} y}{L} \right)} \cos{\left(\frac{\pi N_{z} z}{L} \right)}}{L^{2}}\right)}{2 m_{e}}$
In [14]:
Schr_LHS = sp.simplify(Schr_LHS)
In [15]:
Schr_LHS
Out[15]:
$\displaystyle \frac{\pi^{2} A^{3} h^{2} \left(N_{x}^{2} + N_{y}^{2} + N_{z}^{2}\right) \cos{\left(\frac{\pi N_{x} x}{L} \right)} \cos{\left(\frac{\pi N_{y} y}{L} \right)} \cos{\left(\frac{\pi N_{z} z}{L} \right)}}{2 L^{2} m_{e}}$
In [16]:
# (3) Define and display Right-hand-side = RHS of Schrodinger equation
In [17]:
Schr_RHS = E * F(x,y,z)
In [18]:
Schr_RHS
Out[18]:
$\displaystyle A^{3} E \cos{\left(\frac{\pi N_{x} x}{L} \right)} \cos{\left(\frac{\pi N_{y} y}{L} \right)} \cos{\left(\frac{\pi N_{z} z}{L} \right)}$
In [19]:
# (4) Define final Schrodinger equation
# (logically: Schr_RHS = Schr_LHS
In [20]:
Schr = sp.Eq(Schr_LHS, Schr_RHS)
In [21]:
Schr
Out[21]:
$\displaystyle \frac{\pi^{2} A^{3} h^{2} \left(N_{x}^{2} + N_{y}^{2} + N_{z}^{2}\right) \cos{\left(\frac{\pi N_{x} x}{L} \right)} \cos{\left(\frac{\pi N_{y} y}{L} \right)} \cos{\left(\frac{\pi N_{z} z}{L} \right)}}{2 L^{2} m_{e}} = A^{3} E \cos{\left(\frac{\pi N_{x} x}{L} \right)} \cos{\left(\frac{\pi N_{y} y}{L} \right)} \cos{\left(\frac{\pi N_{z} z}{L} \right)}$
In [22]:
# (5) Solve Schrodinger equation for E
In [23]:
# solving for E is surprisingly easy
# (because we have already inserted known solution for F
solution = sp.solve(Schr,E)
In [24]:
# sp.solve yields list of solutions
# (here we have just one solution = list containing just one element
solution
Out[24]:
$\displaystyle \left[ \frac{\pi^{2} h^{2} \left(N_{x}^{2} + N_{y}^{2} + N_{z}^{2}\right)}{2 L^{2} m_{e}}\right]$
In [25]:
# (6) Slightly adjust and print the final solution
In [26]:
# We take the first (and the only) solution
# of Schr.equation from section (5) and print it as an equation
sp.Eq(E,solution[0])
Out[26]:
$\displaystyle E = \frac{\pi^{2} h^{2} \left(N_{x}^{2} + N_{y}^{2} + N_{z}^{2}\right)}{2 L^{2} m_{e}}$
In [27]:
# The quantum numbers Nx,Ny,Nz can be combined into one quantum number n,
# which gives the final relation for energy of an electron in a cube
n = sp.symbols('n', integer=True, positive=True)
sp.Eq(E,solution[0]).subs(Nx**2+Ny**2+Nz**2,n**2)
Out[27]:
$\displaystyle E = \frac{\pi^{2} h^{2} n^{2}}{2 L^{2} m_{e}}$
In [28]:
# CONCLUSIONS
# 1) We inserted (known) characteristic function F(x,y,z)
#    into (known) Schrodinger equation of electron in a cube.
# 2) We solved the Schr.equation from (1) for E,
#    which gave us characteristic values = possible energies E of eln in cube.
# 3) As the quantum numbers (Nx,Ny,Nz,n) are integers,
#    the eln-in-cube cannot have arbitrary energy, but just some distinct values
#    => this is called energy quantization
#    => the electron energy is quantized