1

Im asked to draw/plot the graph for the modulus function f(m) = m^7 modulo 137. I tried to do that in LaTeX with the package „pgfplots“ following the instructions from the official overleaf tutorial: https://de.overleaf.com/learn/latex/Pgfplots_package#Reference_guide However this doesnt work at all. My whole document crashes as soon as I compile while using the function from above. I used the same code as I did for plotting a „normal“ function: If I leave out the „mod 137“ then it plots perfectly.

\documentclass{article}
\usepackage[margin=0.25in]{geometry}
\usepackage{pgfplots}
\pgfplotsset{width=10cm,compat=1.9}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
    axis lines = left,
    xlabel = \(m\),
    ylabel = {\(f(m)\)},
    xmin=0, xmax=5,
    ymin=0, ymax=100,
]

\addplot [ domain=0:10, samples=100, color=black, ] {x^7 \mod 137}; \addlegendentry{(f(m))}.

\end{axis} \end{tikzpicture}

\end{document}

Help of any kind is very much appreciated!

! Undefined control sequence.
\pgfplots@addplotimpl@expression@yEXPR ->x^7 \mod 
                                                  137
l.20 {x^7 \mod 137};
Stefan Pinnow
  • 29,535
Math56
  • 11

1 Answers1

1
\documentclass[border=1 cm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
    axis lines = left,
    xlabel = \(m\),
    ylabel = {\(f(m)\)},
    xmin=0, xmax=5,
    ymin=0, ymax=150,
]
\addplot[
    domain=0:3.5, 
    samples=1000, 
    y filter/.expression={x>2&&y<30*(x-2)?0:(x>2&&y>137-30*(x-2)?137:y)},
    forget plot, %workaround
    ] {mod(x^7,137)};
\fill (3.5,0) rectangle (5,137);
\addlegendimage{line legend} %workaround
\addlegendentry{\(f(m)\)}
\end{axis}
\end{tikzpicture}
\end{document}

Graph of mod(x^7,137)