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?






    axis x line=center,
    axis y line=center,
    xlabel style={below right},
    ylabel style={above left},
    \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$} ;


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 '19 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 '19 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 '19 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. Mar 14 '19 at 12:43
  • 2
    See tex.stackexchange.com/a/438911/2388. Exchange all occurences of xelatex by pdflatex. Mar 15 '19 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.