$\langle n \rangle$ from Q-function

Using QuTiP features, we show that the expectation value $\langle n\rangle$ can be found from the Q-function by placing the operator in antinormal order: $\langle n\rangle = \hat{a}^\dagger\hat{a} = \hat{a}\hat{a}^\dagger - 1$ therefore $\mathrm{tr}\{\hat\rho\hat{a}\hat{a}^\dagger\} = \langle n \rangle + 1$ and we can use the Q-function to find this expectation value as well:

$\langle \hat{a}\hat{a}^\dagger\rangle = \int Q(x,y)\alpha \alpha^* dxdy$ where $\alpha = \frac{1}{\sqrt{2}} (x + iy)$

this gives:

$\langle n \rangle = \frac{1}{2}\int Q(x,y)(x^2+y^2) dxdy - 1$


In [1]:
%pylab inline
from qutip import *
from scipy import *


Populating the interactive namespace from numpy and matplotlib

In [2]:
qvec = linspace(-10,10,200)
pvec = linspace(-10,10,200)

In [3]:
N=50
alpha = sqrt(5)  # alpha is sqrt of <n>
cdm = coherent_dm(N,alpha)

In [4]:
hinton(cdm)


Out[4]:
<matplotlib.axes.AxesSubplot at 0x106c7ce50>

In [5]:
(cdm*destroy(N)*create(N)).tr()  # this is <n> + 1, agrees with our specification of alpha


Out[5]:
(5.999999999994867+0j)

In [11]:
qdist = qfunc(cdm,qvec,pvec)

In [12]:
imshow(qdist)


Out[12]:
<matplotlib.image.AxesImage at 0x10a4d5fd0>

In [13]:
qdist = qdist/qdist.sum()

In [14]:
q, p = meshgrid(qvec,pvec)

In [16]:
(qdist*0.5*(q**2+p**2)).sum() - 1


Out[16]:
4.9999999998669624

$\hat{X} = \frac{1}{\sqrt{2}}(\hat{a} + \hat{a}^\dagger)$

$\hat{Y} = \frac{1}{i\sqrt{2}}(\hat{a} - \hat{a}^\dagger)$


In [17]:
X = 1/sqrt(2)*(destroy(N) + create(N))
Y = -1j*1/sqrt(2)*(destroy(N) - create(N))

In [19]:
(cdm*0.5*(X**2+Y**2)).tr() - 0.5 # also agrees with our definitions of X and Y


Out[19]:
(4.999999999994949+0j)

In [14]:
from qutip.ipynbtools import version_table

version_table()


Out[14]:
SoftwareVersion
Cython0.19.2
SciPy0.13.2
QuTiP2.2.0
Python2.7.6 |Anaconda 1.8.0 (x86_64)| (default, Jan 10 2014, 11:23:15) [GCC 4.0.1 (Apple Inc. build 5493)]
IPython1.1.0
OSposix [darwin]
Numpy1.7.1
matplotlib1.3.1
Thu Jan 30 14:09:31 2014

In [ ]: