1% Photon number distribution (Sec. IV.A)
2% P_n = |<n|psi>|^2. Poissonian for a coherent state, monotonic for a
3% thermal state. Two bar plots are produced.
5clear; % Clear memory
6clc; % Clear the command window/screen
7d = 15; % dimension of the field
8I = eye(d);
10%%%%%%%% Coherent state
11alpha = 2; % amplitude of the coherent state
12Coh = 0; % initialization
13for x = 0:d-1
14 Coh = Coh + exp(-norm(alpha)^2/2)*alpha^x/sqrt(prod(1:x))*I(:,x+1);
15end
16for n = 0:d-1
17 PnC(n+1) = norm(I(:,n+1)'*Coh)^2; % Probability of |n> in coherent state
18end
20%%%%%%%% Thermal state
21nth = 0.5; % average number of photons in the thermal state
22RhoTh = 0;
23for x = 0:d-1
24 RhoTh = RhoTh + nth^(x)/(1+nth)^(x+1)*I(:,x+1)*I(:,x+1)';
25end
26for n = 0:d-1
27 PnTh(n+1) = I(:,n+1)'*RhoTh*I(:,n+1); % Probability of |n> in thermal state
28end
30%%%%%%%%%% Bar plots
31n = 0:d-1;
32figure(1)
33bar(n, PnC)
34title('Coherent state \alpha = 2'); xlabel('n'); ylabel('P_n')
36figure(2)
37bar(n, PnTh)
38title('Thermal state n_{th} = 0.5'); xlabel('n'); ylabel('P_n')