Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
| Download
Views: 1717
Image: ubuntu2004
Kernel: Python 3 (system-wide)

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.

from sympy import * from sympy.physics.hydrogen import *
n = symbols("n") ell = symbols("ℓ") m = symbols("m")
r, theta, phi = symbols("r θ ϕ", real=True)
# Unperturbed energy of state n E_nl(n)

12n2\displaystyle - \frac{1}{2 n^{2}}

# 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}}

# 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}}

# 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

# 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

# perform the integration _.doit()

1282243\displaystyle \frac{128 \sqrt{2}}{243}

# approximate this in decimal form N(_)

0.744935539027803\displaystyle 0.744935539027803

_*5.292e-11 # convert from atomic units to SI units

3.942198872535131011\displaystyle 3.94219887253513 \cdot 10^{-11}

_**2

1.554093195061731021\displaystyle 1.55409319506173 \cdot 10^{-21}

_21**2

0.554928957306644\displaystyle 0.554928957306644