22

I have the following pgfplots code:

\begin{tikzpicture}
\begin{axis}[domain=-8:2]
\foreach \i in {-10,-9.8,...,10} {\addplot+[smooth] {-x/\i+\i};}%
\end{axis}
\end{tikzpicture}

I need several line-plots in order for the parabolic pattern to emerge, hence the for loop with a 0.2 increment. Unfortunately, this gives me the dimension too large error. What can I do?

26

Besides the obvious 1/0 division, the question is not about math but about TeX, i.e. why pgfplots fails. pgfplots probably complains because whatever internal represenation of 1/0 is "too large" to be plotted. The solution is to use restrict y to domain

\documentclass[12pt]{article}

\usepackage{pgfplots}

\begin{document}
\begin{tikzpicture}
\begin{axis}[domain=-8:2, restrict y to domain=-10:10]
\foreach \i in {-10,-9.8,...,10} {\addplot+[no markers, solid, smooth] {-x/\i+\i};}%
\end{axis}
\end{tikzpicture}

\end{document}

(Having said that, it is anyway dangerous to allow a division by zero in general.)

emerging parabola

  • 10
    Another day, another pgfplots option :) – Ryan Reich Jan 19 '12 at 21:26
5

In the middle of the loop \i=0, so that there will be a division by zero. Mathematics generally does not like that (though interestingly the code compiles on my computer). So you have to split the loop into two loops, excluding zero:

\documentclass[12pt]{article}

\usepackage{pgfplots}

\begin{document}
\begin{tikzpicture}
\begin{axis}[domain=-8:2]
    \foreach \i in {-10,-9.8,...,-0.2} {\addplot+[smooth] {-x/\i+\i};}%
    \foreach \i in {0.2,0.4,...,10} {\addplot+[smooth] {-x/\i+\i};}%
\end{axis}
\end{tikzpicture}

\end{document}

result

  • 2
    Once division by zero is allowed, 1 becomes zero, then all hell breaks loose. :-) – Matthew Leingang Mar 18 '11 at 18:34
  • @Matthew: Now, what does that say about my computer? – Caramdir Mar 18 '11 at 18:42

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.