I am trying to plot the Thomae function, which is defined in the following way:
Now, I went through this answer, but unfortunately, could not grasp much. My idea is simple. Run two nested loops for the rationals and plot the points. What I have done is the following:
\documentclass{standalone}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}[scale=5]
\node [fill, circle, inner sep=0.5pt] at (0,0) {};
\node [fill, circle, inner sep=0.5pt] at (1,1) {};
\foreach [evaluate=\n as \den using \n-1] \n in {2,...,85}
\foreach \m in {1,...,\den}
\node [fill, circle, inner sep=0.5pt] at ({\m/\n},{1/\n}) {};
\end{tikzpicture}
\end{document}
I am getting stuck at the gcd
part. I do not know the proper usages and syntaxes of pgfmathsetmacro
and the conditional ifthenelse
statements. Please help.