/gaussianBeam.m

http://github.com/gallamine/Photonator · Objective C · 58 lines · 50 code · 8 blank · 0 comment · 1 complexity · 444453d6b617a1bb1b7e6a6199c99358 MD5 · raw file

  1. % beam.m
  2. % A MATLAB program
  3. % Steven L. Jacques, Dec. 1998.
  4. %
  5. % Generates the probability density function p(r)
  6. % and the relative irradiance E(r) [mm^-2]
  7. % for a 2D Gaussian beam profile associated with
  8. % a laser beam. Histograms based on 10,000 random numbers
  9. % are created, and compared with the analytic expressions.
  10. %
  11. % Two figures are generated: p(r) and E(r).
  12. %
  13. close
  14. close
  15. clear
  16. b = 1; % arbitrary choice of 1/e beam radius.
  17. N = 10000; % number of random numbers used
  18. rnd1 = rand(1,N); % create array of random numbers
  19. r1 = b*sqrt(-log(1 - rnd1)); % array of selected values r1
  20. % Note: log() is base e
  21. nb = 30; % number of bins
  22. [n,x] = hist(r1,nb); % n(x) = histo(x=r1) using nb bins
  23. dx = x(3)-x(2); % bin size
  24. n = n/N/dx; % normalize by N and dx
  25. sum(n*dx) % verify that integral equals unity
  26. nr = n./(2*pi*x); % normalize by circumference of ring at r=x
  27. r = (0:.1*b:3*b); % create an array of r values
  28. E = exp(-r.^2/b^2)/(pi*b^2); % calculate an array of E values,
  29. % using a pure 2D Gaussian.
  30. % Create figure of p(r)
  31. figure
  32. plot(x, n,'yo')
  33. hold on
  34. plot(r, E*2*pi.*r,'r-')
  35. xlabel('r')
  36. ylabel('p(r)')
  37. xlabel('r [mm]')
  38. title(['b = ' int2str(b) ' [mm]'])
  39. hold off
  40. % Create figure of E(r)
  41. figure
  42. plot(x,nr,'o')
  43. xlabel('r')
  44. ylabel('p(r)')
  45. hold on
  46. plot(r,E,'r-')
  47. title(['b = ' int2str(b) ' [mm]'])
  48. ylabel('E(r) [mm^-2]')
  49. xlabel('r [mm]')
  50. hold off