dirichlet-function.tex 1.2 KB

12345678910111213141516171819202122232425262728293031323334
  1. \documentclass{article}
  2. \usepackage[pdftex,active,tightpage]{preview}
  3. \setlength\PreviewBorder{2mm}
  4. \usepackage{amssymb,amsmath}
  5. \usepackage{pgfplots}
  6. \begin{document}
  7. \begin{preview}
  8. \begin{tikzpicture}
  9. \begin{axis}[
  10. axis lines=middle,
  11. width=15cm, height=15cm, % size of the image
  12. grid = both,
  13. grid style={dashed, gray!30},
  14. enlargelimits=true,
  15. xmin=-1, % start the diagram at this x-coordinate
  16. xmax= 1, % end the diagram at this x-coordinate
  17. ymin= 0, % start the diagram at this y-coordinate
  18. ymax= 1, % end the diagram at this y-coordinate
  19. /pgfplots/xtick={-1,-0.8,...,1}, % make steps of length 0.2
  20. /pgfplots/ytick={0,0.1,...,1}, % make steps of length 0.1
  21. axis background/.style={fill=white},
  22. ylabel=y,
  23. xlabel=x,
  24. legend style={at={(0.8,0.8)}, anchor=north}]
  25. \addplot[domain=-1:1, ultra thick,samples=100,red] {1};
  26. \addplot[domain=-1:1, ultra thick,samples=100,blue] {0};
  27. \legend{$1 \text{, if } x \in \mathbb{Q}$, $0 \text{, if } x \in \mathbb{R} \setminus \mathbb{Q}$}
  28. \end{axis}
  29. \end{tikzpicture}
  30. \end{preview}
  31. \end{document}