21c62a3Quantum optics in numbl: companion to arXiv:2309.14354Jeremy Magland 1% Average number of photons (Sec. IV.B)
2% <a'a> = <psi|a'a|psi> (pure states), Tr(a'a rho) (mixed states)
3% Number state |4> -> 4, coherent (|alpha|^2 = 3) -> 3, thermal (nth) -> nth.
5clear; % Clear memory
6clc; % Clear the command window/screen
7d = 20; % dimension of the field
8I = eye(d); % identity matrix
10%%%% Number operator
11A = diag(sqrt(1:d-1), 1); % Annihilation operator
12Ad = A'; % Creation operator
13AdA = Ad*A; % Number operator
15%% Number state |4>
16Ket4 = I(:,5); % four-photon state |4>
17AdANumber = Ket4'*AdA*Ket4 % average photon number in the number state
19%% Coherent state
20alpha = sqrt(3); % amplitude of the coherent state
21Coh = 0; % initialization
22for x = 0:d-1
23 Coh = Coh + exp(-norm(alpha)^2/2)*alpha^x/sqrt(prod(1:x))*I(:,x+1);
24end
25AdACoherent = Coh'*AdA*Coh % average photon number in coherent state (= |alpha|^2)
27%%% Thermal state
28nth = 0.85; % assumed average number of photons in the thermal state
29RhoTh = 0;
30for x = 0:d-1
31 RhoTh = RhoTh + nth^(x)/(1+nth)^(x+1)*I(:,x+1)*I(:,x+1)';
32end
33AdAThermal = trace(AdA*RhoTh) % average photon number in thermal state (= nth)