CoCalc Public FilesSkills 2020 / HydrogenSympy.ipynbOpen with one click!
Author: Alyssa Gadsby
Compute Environment: Ubuntu 20.04 (Default)

Hydrogen calculations using sympy

The sympy library does symbolic math. It also includes several useful things in the sympy.physics module, like hydrogen and harmonic oscillator wavefunctions.

In [1]:
from sympy import * from sympy.physics.hydrogen import *
In [12]:
n = symbols("n") ell = symbols("ℓ") m = symbols("m")
In [8]:
r, theta, phi = symbols("r θ ϕ", real=True)
In [14]:
# Unperturbed energy of state n E_nl(n)
12n2\displaystyle - \frac{1}{2 n^{2}}
In [13]:
# Wavefunciton of state |n,ℓ,m> Psi_nlm(n, ell, m, r, phi, theta)
(2rn)(n1)!n4(n+)!2(m+)!(m+)!+(m+)!(m+)!erneimϕLn1(2+1)(2rn)P(m)(cos(θ))π\displaystyle \frac{\left(\frac{2 r}{n}\right)^{ℓ} \sqrt{\frac{\left(n - ℓ - 1\right)!}{n^{4} \left(n + ℓ\right)!}} \sqrt{\frac{2 ℓ \left(- m + ℓ\right)!}{\left(m + ℓ\right)!} + \frac{\left(- m + ℓ\right)!}{\left(m + ℓ\right)!}} e^{- \frac{r}{n}} e^{i m ϕ} L_{n - ℓ - 1}^{\left(2 ℓ + 1\right)}\left(\frac{2 r}{n}\right) P_{ℓ}^{\left(m\right)}\left(\cos{\left(θ \right)}\right)}{\sqrt{\pi}}
In [29]:
# Check a specfic state to compare Psi_nlm(3, 1, 0, r, phi, theta)
2r(42r3)er3cos(θ)54π\displaystyle \frac{\sqrt{2} r \left(4 - \frac{2 r}{3}\right) e^{- \frac{r}{3}} \cos{\left(θ \right)}}{54 \sqrt{\pi}}
In [16]:
# define some aliases z = r * cos(theta) x = r * sin(theta)*cos(phi) y = r * sin(theta)*sin(phi)

Example integrals

Let's calculate 2,1,0z1,0,0=r=0ϕ=02πθ=0πϕ2,1,0zϕ1,0,0r2sinθdrdθdϕ \langle 2,1,0 \vert z \vert 1,0,0\rangle = \int\limits_{r=0}^{\infty} \int\limits_{\phi=0}^{2\pi} \int\limits_{\theta=0}^\pi \phi^*_{2,1,0}\, z\, \phi_{1,0,0}\,r^2\sin\theta\,dr\,d\theta\,d\phi

In [34]:
# Set up some integrals Integral(conjugate(Psi_nlm(2,1,0,r, phi, theta))*z*Psi_nlm(1,0,0,r,phi,theta)*r**2*sin(theta),(phi,0,2*pi),(theta,0,pi),(r,0,oo))
00π02π2r4e3r2sin(θ)cos2(θ)8πdϕdθdr\displaystyle \int\limits_{0}^{\infty}\int\limits_{0}^{\pi}\int\limits_{0}^{2 \pi} \frac{\sqrt{2} r^{4} e^{- \frac{3 r}{2}} \sin{\left(θ \right)} \cos^{2}{\left(θ \right)}}{8 \pi}\, dϕ\, dθ\, dr
In [35]:
# perform the integration _.doit()
1282243\displaystyle \frac{128 \sqrt{2}}{243}
In [21]:
# approximate this in decimal form N(_)
0.744935539027803\displaystyle 0.744935539027803
In [22]:
_*5.292e-11 # convert from atomic units to SI units
3.942198872535131011\displaystyle 3.94219887253513 \cdot 10^{-11}
In [23]:
_**2
1.554093195061731021\displaystyle 1.55409319506173 \cdot 10^{-21}
In [24]:
_21**2
0.554928957306644\displaystyle 0.554928957306644
In [ ]: