%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% CALCULATE THE ENERGY LEVELS OF A 1D PARTICLE-IN-THE-BOX WITH INFINITE WALLS %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
clear all;

% INPUT DATA

Lmin=5.0;       % shortest QD (nm)
Lmax=50.0;      % longest QD (nm)
Lstep=1.0;      % increment of QD size (nm)
m=0.05;         % electron effective mass (times m0)
neig=4;         % number of states to be calculated (starting from ground state)

% CALCULATION

for L_nm=Lmin:Lstep:Lmax % open loop of L

% 1) Convert into atomic units
kdist=0.0529177; % kdist nm = 1 bohr radius
kener=27.21138;  % kener eV = 1 hartree

L=L_nm/kdist;

for i=1:neig
    eners(i)=pi^2*i^2/(2*m*L^2)*kener; % analytic energy (eV)
end
    
% WRITE RESULTS TO DISK

% Write energy to external file
file=fopen('energies2.dat','a'); % open file to append results

fprintf(file,'%10.2f',L*kdist);   % write QD size (nm)
for i=1:neig
    fprintf(file,'%10.3f',eners(i)*1000); % write eigenvalues (meV)
end;
fprintf(file,'\n');

fclose(file);

end; % close loop of L
