0

I am trying to generate a LaTeX pgfplot:

\begin{tikzpicture}
\begin{axis}[
xmin=.2,xmax=.5,
ymin=-.00000000000000001,ymax=.00000000000000001,
xlabel=Distance a (nm),
ylabel=Force F (mJ/nm)
]
\addplot[color=black][domain=.2:.5]{(((6.42*10^(-22))*6)/(x^7))-(((1.02*10^(-25))*13)/(x^14))};
\addplot[color=red][domain=.2:.5]{(((6.42*10^(-22))*6)/(x^7))};
\addplot[color=blue][domain=.2:.5]{-(((1.02*10^(-25))*13)/(x^14))};

\end{axis}
\end{tikzpicture}

This generates the error "dimension too large." What could be wrong?

  • 2
    Welcome to TeX.SX! The number range and the precision supported by TikZ are limited. Try to rewrite the formulas to avoid that intermediate results get out of range or divisors get too close to zero. – Heiko Oberdiek Apr 19 '17 at 5:47
  • The error goes away when I used one less zero for ymax. That is,1e-16. – Troy Apr 19 '17 at 5:48
  • 3
    Welcome to TeX.SE. For future reference, while code snippets are useful in explanations, it is always best to compose a fully compilable MWE that illustrates the problem including the \documentclass and the appropriate packages so that those trying to help don't have to recreate it. – Peter Grill Apr 19 '17 at 5:57
  • 2
    you are way past tex's numerical accuracy there so specifying a range from essentially 0 to 0 . Even with a few less zeros so it doesn't error, you will just be getting essentially rounding error for the y values – David Carlisle Apr 19 '17 at 8:23
  • 1
    Did my answer help you to solve your problem or do you need further assistance? If so, please let us know what you are still missing. Thank you. – Stefan Pinnow Apr 22 '17 at 9:28
2

The error is caused due to a "scaling" problem which can be avoided when you change the domain to the values near the range that is "visible" in the total plot. So simply narrowing down domain to 0.3:0.5 avoids the error.

% used PGFPlots v1.14
\documentclass[border=5pt]{standalone}
\usepackage{pgfplots}
    \pgfplotsset{
        compat=1.3,
    }
\begin{document}
\begin{tikzpicture}
    \begin{axis}[
        xmin=.2,xmax=.5,
        ymin=-1e-17,
        ymax=+1e-17,
        xlabel=Distance a (nm),
        ylabel=Force F (mJ/nm),
        % ---------------------------------------------------------------------
        % changed `domain' to "visible" part of the plots to avoid
        % the "dimension to large" error
        domain=0.3:0.5,
        % ---------------------------------------------------------------------
        % added `smooth' so the plots look better
        smooth,
    ]
        \addplot [color=black] {(((6.42*10^(-22))*6)/(x^7))-(((1.02*10^(-25))*13)/(x^14))};
        \addplot [color=red]   {(((6.42*10^(-22))*6)/(x^7))};
        \addplot [color=blue]  {-(((1.02*10^(-25))*13)/(x^14))};
    \end{axis}
\end{tikzpicture}
\end{document}

image showing the result of above code

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.