%Code from Leathers et al., 2004, NRL report
% Collimated Light In A Non-Scattering Medium
% Monte Carlo code for simulating collimated light in a non-scattering medium
% Assumes a source with E(0)=1
N = 1e5; % number of photons
zd = 3; % position of detector
c = 0.5; % attenuation coefficient
E = 0; % initialize detector response
for i=1:N
z = 0; % initial photon position
s = -log(rand)/c; % geometric path length
z = z + s; % move photon
if z > zd, E=E+1; end % count photons that reach detector
end
E = E/N % normalize detector response