birthday-paradox.tex 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. % Plot of the probability that two people out of n people have the
  2. % same birthday.
  3. % Author: Martin Thoma
  4. % Source: http://martin-thoma.com/plotting-graphs-with-pgfplots/
  5. \documentclass{article}
  6. \usepackage[pdftex,active,tightpage]{preview}
  7. \setlength\PreviewBorder{2mm}
  8. \usepackage{pgfplots}
  9. \usepackage{tikz}
  10. \usetikzlibrary{arrows, positioning, calc}
  11. \begin{document}
  12. \begin{preview}
  13. \begin{tikzpicture}
  14. \begin{axis}[
  15. width=15cm, height=8cm, % size of the image
  16. grid = major,
  17. grid style={dashed, gray!30},
  18. %xmode=log,log basis x=10,
  19. %ymode=log,log basis y=10,
  20. xmin=0, % start the diagram at this x-coordinate
  21. xmax=62, % end the diagram at this x-coordinate
  22. ymin=0, % start the diagram at this y-coordinate
  23. ymax=1.1, % end the diagram at this y-coordinate
  24. /pgfplots/xtick={0,5,...,60}, % make steps of length 5
  25. extra x ticks={23},
  26. extra y ticks={0.507297},
  27. axis background/.style={fill=white},
  28. ylabel=probability of at least one birthday-collision,
  29. xlabel=people,
  30. tick align=outside]
  31. % import the correct data from a CSV file
  32. \addplot table [id=exp]{data.csv};
  33. % mark x=23
  34. \coordinate (a) at (axis cs:23,0.507297);
  35. \draw[blue, dashed, thick](a -| current plot begin) -- (a);
  36. \draw[blue, dashed, thick](a |- current plot begin) -- (a);
  37. % plot the stirling-formulae
  38. \addplot[domain=0:60, red, thick]
  39. {1-(365/(365-x))^(365.5-x)*e^(-x)};
  40. \end{axis}
  41. \end{tikzpicture}
  42. \end{preview}
  43. \end{document}