5

I am using this snippet:

\documentclass{beamer}
\usepackage{pgfplots}

\begin{document}

\begin{tikzpicture}
  \begin{axis}[ 
    xlabel=$x$,
    ylabel={$f(x) = x^{-1}$}
  ] 
    \addplot {x^{-1}}; % this was previously: x^2
  \end{axis}
\end{tikzpicture}

\end{document}

That worked until I changed x^2 to x^{-1}. Now I am getting the following error (there are also lots of errors after it):

PGF Math: Sorry, an internal routine of the floating point unit near '2Y1.0e0]'. (in 'x^{-1}'). \end{frame}

Research:

I could not find many search results except these two questions from Tex SE:

Unfortunately, they seem to be unrelated since their problem is caused by a foreach construct which I don't even have in my code.

My system:

  • MiKTeX-pdfTeX 2.9.4535 (1.40.13) (MiKTeX 2.9)
  • PdfLaTeX
  • Document class: Beamer
  • 4
    The argument of \addplot should be x^(-1), not x^{-1}. Since the resulting plot is still ugly (a value near 0 is much too large), I'll let someone with more pgfplots knowledge write a proper answer. – Bruno Le Floch Nov 18 '13 at 21:56
  • You need some xmin>0 or you will always get an error. – John Kormylo Nov 18 '13 at 22:05
8

As Bruno commented, pgfmath and pgfplots with fpu use parentheses for nested operations and when you provide braces, -1 passes directly to the computation bypassing the fpu conversion.

I would suggest using 1/x for less grey hair and powers of (1/x) avoiding baldness.

\documentclass{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.9}
\begin{document}
\begin{tikzpicture}
  \begin{axis}[
    domain=0:1,
    samples=100,
    restrict y to domain=0:10,
    xlabel=$x$,
    ylabel={$f(x) = x^{-1}$}
  ] 
    \addplot+[no marks] {x^(-1)};
  \end{axis}
\end{tikzpicture}
\end{document}

enter image description here

  • Thanks, that worked perfectly! I guess I'll look up all those properties in the documentation now :) – ComFreek Nov 19 '13 at 15:27

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.