Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Chapter 12 - Simple Harmonic Oscillator

Several examples that make use of the built-in Simple Harmonic Oscillator tools:

from numpy import sqrt,linspace,exp
from qutip import *
import matplotlib.pyplot as plt
%matplotlib inline
N = 40 # size of the Hilbert space.
       # N needs to be large enough that matrix is not truncated
a = destroy(N)
n = a.dag()*a

Define a coherent state with α=2:\alpha = 2:

psi = coherent(N,1)
psi
Loading...

Expectation value n\langle n\rangle:

psi.dag()*n*psi
(1+0j)
# Convert to a density matrix:
psi_dm = ket2dm(psi)
psi*psi.dag()
Loading...
# Fock state distribution of the coherent state:
plot_fock_distribution(psi_dm)
(<Figure size 640x480 with 1 Axes>, <Axes: xlabel='Fock number', ylabel='Occupation probability'>)
<Figure size 640x480 with 1 Axes>

Also look at other coherent states:

# With larger N and α:
plot_fock_distribution(coherent_dm(100,6))
(<Figure size 640x480 with 1 Axes>, <Axes: xlabel='Fock number', ylabel='Occupation probability'>)
<Figure size 640x480 with 1 Axes>

And some other density matrices, like a fock-state (or n eigenstate):

# With a Fock state (number state):
plot_fock_distribution(fock_dm(20,2))
(<Figure size 640x480 with 1 Axes>, <Axes: xlabel='Fock number', ylabel='Occupation probability'>)
<Figure size 640x480 with 1 Axes>
fock(20,2)
Loading...

And a thermal state:

# A thermal state has decaying amplitudes
plot_fock_distribution(thermal_dm(20,2))
(<Figure size 640x480 with 1 Axes>, <Axes: xlabel='Fock number', ylabel='Occupation probability'>)
<Figure size 640x480 with 1 Axes>

Finally, can visualize the phasor using what is called the Wigner function:

xvec = linspace(-10,10,200) # Create an array for the phase space coordinates.
plt.imshow(wigner(coherent(40,5j)+coherent(40,-5j),xvec,xvec), extent=[-10,10,-10,10]) # contour plot of Wigner function
<Figure size 640x480 with 1 Axes>