1% Hamiltonian for the electromagnetic field (Sec. III.B)
2% H = hbar*omega*(a'a + 1/2 I)
3% We set hbar = omega = 1 to express energies in units of hbar*omega.
5clear; % Clear memory
6clc; % Clear the command window/screen
7d = 6; % dimension of the operator
8I = eye(d); % identity matrix
9hbar = 1;
10omega = 1; % frequency of the cavity field
11A = diag(sqrt(1:d-1), 1); % Annihilation operator
12Ad = A'; % Creation operator
13H = hbar*omega*(Ad*A + (1/2)*I) % Hamiltonian (diagonal: 0.5, 1.5, 2.5, ...)