34

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?

0

2 Answers 2

41

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

1
  • 17
    Another day, another pgfplots option :)
    – Ryan Reich
    Commented Jan 19, 2012 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
  • 2
    Once division by zero is allowed, 1 becomes zero, then all hell breaks loose. :-) Commented Mar 18, 2011 at 18:34
  • @Matthew: Now, what does that say about my computer?
    – Caramdir
    Commented Mar 18, 2011 at 18:42

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .