# PGFplot Dimension too large/TeX Capacity Exceeded after reduction in domain and range

In trying to graph the intersection of 3^x and x^3, I was shrinking the domain to properly show one of the intersections. However, once I reduce the domain, I get either Dimension too large, or TeX Capacity Exceeded.

Furthermore, there appears to be at least 6 intersection points (when there should only be one), and the intersection point appears to be in the wrong spot compared to manually pin pointing the intersection. Is this just a round-off issue?.

\documentclass{article}
\usepackage{pgfplots}
\usetikzlibrary{intersections}

\begin{document}

%% Uncommenting these two results in TeX Capacity exceeded
%\newcommand*{\XAxisMin}{2.47805}%
%\newcommand*{\XAxisMax}{2.47810}%

% These two settings produce a graph
\providecommand*{\XAxisMin}{2.47500}%
\providecommand*{\XAxisMax}{2.48000}%

\pgfmathdeclarefunction{GivenF}{1}{\pgfmathparse{(#1)^(3)}}
\pgfmathdeclarefunction{GivenG}{1}{\pgfmathparse{(3)^(#1)}}

\newcommand*{\ShowIntersection}[3]{
\fill
[name intersections={of=#1 and #2, name=i, total=\t}]
[brown, opacity=1, every node/.style={black, opacity=1}]
\foreach \s in {1,...,\t}{(i-\s) circle (3pt)
node [above left, blue] {#3}};
}

\begin{tikzpicture}
\begin{axis}[xmin=\XAxisMin, xmax=\XAxisMax, ymin=15.16, ymax=15.26]

smooth,ultra thick,blue,name path global=GraphF]
{GivenF(x)} node [below left, xshift=-1.0em] {$y=x^3$};

smooth,ultra thick,red,name path global=GraphG]
{GivenG(x)} node [above right, yshift=5.0ex] {$y=3^x$};

% Manually mark where I think the intersection should be
node [left] {$(2.478053,15.2171)$};%

% Results in at least 6 intersection points
\ShowIntersection{GraphF}{GraphG}{$(2.478053,15.2171)$}
\end{axis}
\end{tikzpicture}
\end{document}


The \ShowIntersections is from Intersections in PGFplots.

-
Please make sure that all images are uploaded using the official stackexchange interface, i.e. the image icon on top of the text field (shortcut: CTRL+G). This ensures that all images are always accessible and do not expire. –  Martin Scharrer Aug 3 '11 at 8:14

To answer half your question: the mathematical error appears to be a result of approximations in pgf's implementation of the ln function:

\pgfmathparse{3^2.478053}\pgfmathresult


gives 15.2156 rather than 15.2171. So it may be better to use plot gnuplot, or to produce tables of values in your favourite mathematical software and then plot file or plot table.

The "capacity exceeded" error goes away, and I get the correct intersection, if I use plot gnuplot, but I don't know what causes it in the first place...

-
Computing intersections of almost parallel lines is instable; i.e. one looses a lot of precision in the attempt due to amplification of rounding errors. This issue (which is inherent to the application and has nothing to do with pgfplots) combined with the low accuracy of pgf (intersections) and pgfplots (coordinates) causes the problem. So, plot gnuplot appears to be a good choice. –  Christian Feuersänger Aug 5 '11 at 15:11
That explains the intersections issue, but I was attempting to make the lines not almost parallel by zooming in and got the errors. –  Peter Grill Aug 9 '11 at 4:21
But the calculations are done before they are scaled to the current graph, so this won't have any effect on the errors. –  Ant Aug 9 '11 at 9:48