1

I 'm trying to draw the plot of f(x)=sin(1/x) with pgfplot, but I get an error message:

! TeX capacity exceeded, sorry [main memory size=3000000].

I realized that when I delete one of the packages marked with %!!! in my code, everything is all right. This is the log-file.

What is going wrong?

\documentclass[a4paper,11pt,twoside]{book}
\usepackage[a4paper,left=2.5cm,right=2.5cm,top=2.5cm,bottom=2.5cm]{geometry}
\usepackage[english,greek]{babel}
\usepackage[utf8]{inputenc}

\usepackage{siunitx}%!!!
\usepackage{mathtools}%!!!
\usepackage{subcaption}%!!!
\usepackage[most]{tcolorbox}%!!!
\usepackage{fancybox}%!!!
\usepackage{wasysym}%!!!    

\usepackage{pgfplots}
\pgfplotsset{compat=1.16}   

\usepackage{tikz}
\usetikzlibrary{shapes,snakes}%!!!
\usetikzlibrary{shadows.blur}%!!!
\usetikzlibrary{decorations.text}%!!!
\usetikzlibrary{calc,patterns,angles,quotes,decorations.pathreplacing}%!!!
\usetikzlibrary{spy}%!!!
\usetikzlibrary{positioning,shapes,fit,arrows}%!!!

\begin{document}

\begin{center}
    \begin{tikzpicture}[>=latex]
    \begin{axis}[
    axis x line=center,
    axis y line=center,
    xlabel={$x$},
    ylabel={$y$},
    xlabel style={below right},
    ylabel style={above left},
    xmin=-1.5,
    xmax=1.5,
    ymin=-1.2,
    ymax=1.2,
    ticks=none,
    height=0.3\textwidth,
    width=0.6\textwidth,]
    \addplot[domain=0.01:1.5, thin,samples=5000] {sin(deg(1/(x)))};
    \addplot[domain=-1.5:-0.01, thin,samples=5000] {sin(deg(1/(x)))};
    \node at (axis cs:1.4,0.8) {$C_f$} ;
        \end{axis}
        \end{tikzpicture}   
\end{center}

\end{document}

Thanks in advanced!!!

  • 2
    For me it also compiles using TeX Live 2018 frozen. Are you sure all packages are up to date? both as user and admin? – daleif Mar 14 at 11:04
  • 2
    MikTeX console can update as both user and admin, see miktex.org/howto/miktex-console under "Operation Mode", you need to update both, as the user part (the default) only updates the packages you installed – daleif Mar 14 at 11:30
  • 1
    It is a common problem that plots with too many points (or where too many things need to be calculated) can cause TeX to run out of memory. You could switch to LuaTeX, which has dynamic memory allocation and should not run out of memory that quickly (of course memory is still limited by your hardware), you could think about externalising the picture (cf. tex.stackexchange.com/q/398753/35864, if it compiles in a smaller document at all) or just produce the graph with an external application. Of course you could also choose a smaller samples value: 5000 is a lot. – moewe Mar 14 at 11:30
  • 2
    The document compiles for me, but it uses 2999187 words of memory. If your miktex has only 3000000 reserved that's quite near the exhaustion point. You should enlarge the memory. – Ulrike Fischer Mar 14 at 12:43
  • 2
    See tex.stackexchange.com/a/438911/2388. Exchange all occurences of xelatex by pdflatex. – Ulrike Fischer Mar 15 at 8:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.