Teaching Quantum Mechanics with Python and Jupyter

Andrew MC Dawes

@drdawes

github.com/amcdawes/QMlabs


In [18]:
from qutip import *
import matplotlib.pyplot as plt
import numpy as np
%matplotlib inline

In [6]:
coherent_dm(5,2)


Out[6]:
Quantum object: dims = [[5], [5]], shape = (5, 5), type = oper, isherm = True\begin{equation*}\left(\begin{array}{*{11}c}0.022 & 0.032 & 0.077 & 0.029 & 0.117\\0.032 & 0.047 & 0.113 & 0.042 & 0.171\\0.077 & 0.113 & 0.271 & 0.100 & 0.411\\0.029 & 0.042 & 0.100 & 0.037 & 0.152\\0.117 & 0.171 & 0.411 & 0.152 & 0.623\\\end{array}\right)\end{equation*}

Simulate a spin-1/2 system in an external magnetic field.


In [52]:
omega = 2*np.pi
H = 0.707*sigmaz() + 0.707*sigmax()
a=1/np.sqrt(2)
b=a
psi0 = a*basis(2,1) + b*basis(2,0)
t = np.linspace(0,10)
Sz = 1/2*sigmaz()

In [55]:
result1 = sesolve(H,psi0,t,[Sz])

In [56]:
for ex in result1.expect:
    plt.plot(omega*t/np.pi,ex)



In [ ]:


In [ ]: