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 *
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]:
In [5]:
(cdm*destroy(N)*create(N)).tr() # this is <n> + 1, agrees with our specification of alpha
Out[5]:
In [11]:
qdist = qfunc(cdm,qvec,pvec)
In [12]:
imshow(qdist)
Out[12]:
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]:
$\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]:
In [14]:
from qutip.ipynbtools import version_table
version_table()
Out[14]:
In [ ]: