%Fig_4_8.m
%diffusion in 1-D
%
%plotting parameters + fontsizes
clear all;
clf;

FS      = 28;	%label fontsize 18
FSN     = 28;	%number fontsize 16
LW      = 2;	%linewidth 2

% Change default axes fonts.
set(0,'DefaultAxesFontName', 'Times New Roman')
set(0,'DefaultAxesFontSize', FSN)

% Change default text fonts.
set(0,'DefaultTextFontname', 'Times New Roman')
set(0,'DefaultTextFontSize', FSN)

%constants
kelvin=300.0;					%Absolute temperature (K)

m0=9.10956e-31;					%Bare electron mass (kg)
m1=0.5;							%Effective electron mass
echarge=1.60219e-19;			%Electron charge (C)
hbar=1.0545928e-34;				%Planck's constant (J s)
kB=8.617e-5;					%Boltzmann's constant (eV K-1)

%parameters

Ntraj=100;%number of trajectories 100 10
N    =400; %number of steps 400 10
tau  =0.1e-12; %relaxation time constant (ps)

vel  =sqrt(kB*echarge*kelvin/m0);


ttl=(['Electron diffusion, T=',num2str(kelvin),'K, \tau=',...
    num2str(tau*1e12),'ps, v=',num2str(abs(vel),'%5.0f'),'ms^{-1}']);

for k=1:Ntraj
%initialize a new set of trajectories
tp=zeros(N,1);
x =zeros(N,1);
t =-tau*2*log(rand(N,1));
vp=2*(round(rand(N,1))-0.5);
vinit=2*(round(rand(1))-0.5);       
for n=2:N
%  x(n)=x(n-1)+vel*vinit*t(n)*(-1)^n;%every collision reverses direction;
x(n)=x(n-1)+vel*vinit*t(n)*vp(n,1);%every collision random direction;
 tp(n)=t(n)+tp(n-1);   
end

figure(1)
plot(tp*1e12,x*1e6,'k','LineWidth',LW)

hold on

end
xlabel('Time, \it{t}\rm (ps)','FontSize',FS);
ylabel('Position, \it{x}\rm (\mum)','FontSize',FS);
%axis([0 max(tp*1e12) -abs(max(x*1e6)) abs(max(x*1e6))]);
%axis([0 90 -1 1]);
%title(ttl,'FontSize',FS);








