# Using modulo operation to draw graph

I have a graph that consists of x and y from Z/11. Is it possible to programmatically draw the lines that have a slope of 2?

Like from (0,0) to (5,10) and (6,12) would become (6,1) because of modulo 11. Just like the graph below.

For that graph I use the following code. But I have to manually calculate the start and end points.

    \begin{tikzpicture}
\coordinate (Origin)   at (0,0);
\coordinate (XAxisMin) at (0,0);
\coordinate (XAxisMax) at (11,0);
\coordinate (YAxisMin) at (0,0);
\coordinate (YAxisMax) at (0,11);

\draw [thick, gray,-latex] (XAxisMin) -- (XAxisMax);% Draw x axis
\draw [thick, gray,-latex] (YAxisMin) -- (YAxisMax);% Draw y axis

\foreach \x in {0,1,...,10}{% Two indices running over each
\foreach \y in {0,1,...,10}{% node on the grid we have drawn
\node[draw,circle,inner sep=1pt,fill] at (\x,\y) {};
% Places a dot at those points
}
}

\draw [thin, blue,-latex] (Origin) -- (5,10);
\draw [thin, blue,-latex] (6,1) -- (10,9);
\end{tikzpicture}

-

You can use the Mod(<num>,<base>) function to get the modulus, but I didn't understand if you want it in the for each loop or not so here is for the loop

\documentclass{article}
\usepackage{tikz}

\begin{document}
\begin{tikzpicture}
\coordinate (Origin)   at (0,0);
\coordinate (XAxisMin) at (0,0);
\coordinate (XAxisMax) at (11,0);
\coordinate (YAxisMin) at (0,0);
\coordinate (YAxisMax) at (0,11);

\draw [thick, gray,-latex] (XAxisMin) -- (XAxisMax);% Draw x axis
\draw [thick, gray,-latex] (YAxisMin) -- (YAxisMax);% Draw y axis

\foreach \x in {0,1,...,10}{% Two indices running over each
\foreach \y[evaluate=\y as \yi using {Mod(\y,11)}] in {0,1,...,15}{
\node[draw,circle,inner sep=1pt,fill] at (\x,\y) {};
\draw (0,0) -- (\x,\yi);
% Places a dot at those points
}
}
\end{tikzpicture}
\end{document}


I hope I understood it correctly,

\documentclass{article}
\usepackage{tikz}

\begin{document}
\begin{tikzpicture}
\coordinate (Origin)   at (0,0);
\coordinate (XAxisMin) at (0,0);
\coordinate (XAxisMax) at (11,0);
\coordinate (YAxisMin) at (0,0);
\coordinate (YAxisMax) at (0,11);

\draw [thick, gray,-latex] (XAxisMin) -- (XAxisMax);% Draw x axis
\draw [thick, gray,-latex] (YAxisMin) -- (YAxisMax);% Draw y axis

\draw  (0,0)  \foreach \x in {1,...,11}{
\foreach \y in {1,...,11}{
node[draw,circle,inner sep=1pt,fill] at (\x-1,\y-1) {}
-- ({Mod(\x,11)},{Mod(2*\x,11)})
}
};
\end{tikzpicture}
\end{document}


-
Hi. That is already pretty nice. But it should calculate from a starting point and then continue until it gets back to the starting point.. (0,0) --> (1,2) --> (2,4) --> (3,6) --> (4,8) --> (5,10) --> (6,1) --> (7,3) --> (8,5) --> (9,7) --> (10,9) --> (0,0). This behaviour is due to the modulo with a slope of 2. –  Chris Apr 1 '14 at 14:40
I guess the calculation would be x=x mod 11 and y = (x+2) mod 11 for y. While –  Chris Apr 1 '14 at 14:44
It is almost perfect yes. The line (0,0) -> (10,9) should not exist and (5,10) --> (6,1) should also not exist. Plus the line that starts at (6,1) should go all the way down to the x axis.. (5.5,0) would it be.. –  Chris Apr 1 '14 at 15:30