Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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?.graph

\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]

    \addplot[domain=\XAxisMin:\XAxisMax, samples=400,
        smooth,ultra thick,blue,name path global=GraphF]
        {GivenF(x)} node [below left, xshift=-1.0em] {$y=x^3$};

    \addplot[domain=\XAxisMax:\XAxisMin, samples=400,
        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
    \addplot [mark=*] coordinates{(2.478053,15.2171)}%
        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.

share|improve this question
    
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
add comment

1 Answer

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...

share|improve this answer
    
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
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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