0

I am plotting a function, but always get"dimension too large" error. I have searched online and tried many ways without a success. Appreciate your suggestion.

\usetikzlibrary {spy}
\def\distance{1cm}%
\vspace{\distance}
\def\distance{2cm}%
\hspace{\distance}%
\begin{tikzpicture}
\begin{loglogaxis}[xlabel=$T$,ylabel=$\sigma$,xmin=1e-3, xmax=1e2, ymin=1e-1, ymax=1e18,restrict y to domain=1e-1:1e18]
\addplot [black,thick,domain=1e-3:1e2, y domain=1e-1:1e18,restrict y to domain=1e-1:1e18, samples=200]{x*(exp(4*10/x)-exp(3*10/x))};
\addplot[red,thick,domain=1e-3:1e2,y domain=1e-1:1e18,restrict y to domain=1e-1:1e18,  samples=400]{x*(exp(12*10/x)-exp(11*10/x))};
\end{loglogaxis}
\end{tikzpicture}
  • 3
    Show a small but complete document that demonstrates the error. This will make it much easier to reproduce your problem. – Ulrike Fischer Apr 26 '18 at 7:16
1

Here is exp(120000):

\documentclass{article}

\usepackage{xintexpr}

\xintDigits := 24;

\xintverbosetrue

\xintdeffloatvar e := `+`(rseq(1{;} (@<1e-24)?{abort}{@/i}, i = 1++));

\begin{document}

\xintthefloatexpr [16] e**120000\relax

\end{document}

This gives 2.176849428771918e52115. But the pgf manual says

The fpu provides a replacement set of math commands which can be installed in isolated placed to achieve large data ranges at reasonable accuracy. It provides at least the IEEE double precision data range, -10^324...+10^324

This suggests that the exponent 52115 is too big. There is a footnote in the pgf manual saying the exponent is a 32bit integer but it is not clear what that means. I don't know what is the exact maximal exponent, but for comparison the xfp is limited to 9999 as exponent.


Alternative: don't use loglogaxis.

Hopefully, I got the math right:

\documentclass{article}
\usepackage{pgfplots}
%\usetikzlibrary {spy}
%\usetikzlibrary{fpu}
\begin{document}
\begin{tikzpicture}
% \begin{loglogaxis}[xlabel=$T$,ylabel=$\sigma$,xmin=1e-3, xmax=1e2, ymin=1e-1, ymax=1e18,restrict y to domain=1e-1:1e18]
% \addplot [black,thick,domain=1e-3:1e2, y domain=1e-1:1e18,restrict y to domain=1e-1:1e18, samples=200]{x*(exp(4*10/x)-exp(3*10/x))};
% \addplot[red,thick,domain=1e-3:1e2,y domain=1e-1:1e18,restrict y to domain=1e-1:1e18,  samples=400]{x*(exp(12*10/x)-exp(11*10/x))};
% \end{loglogaxis}
% \begin{axis}[xlabel=$\log T$,ylabel=$\log \sigma$,xmin=-3, xmax=2, ymin=-1, ymax=18,restrict y to domain=-1:18]
% \addplot [black,thick,domain=-3:2, y domain=-1:18,restrict y to domain=-1:18,
% samples=200]{x + 40*exp(-x) + ln(1 - exp(-10/exp(x)))};
% \addplot[red,thick,domain=-3:2,y domain=-1:18,restrict y to domain=-1:18,
% samples=400]{x + 120*exp(-x) + ln(1 - exp(-10/exp(x)))};
% \end{axis}
\begin{axis}[xlabel=$\log T$,ylabel=$\log \sigma$,xmin=-3, xmax=2, ymin=5, ymax=50,restrict y to domain=5:50]
\addplot [black,thick,domain=-3:2, y domain=5:50,restrict y to domain=5:50,
samples=200]{x + 40*exp(-x) + ln(1 - exp(-10*exp(-x)))};
\addplot[red,thick,domain=-3:2,y domain=5:50,restrict y to domain=5:50,
samples=400]{x + 120*exp(-x) + ln(1 - exp(-10*exp(-x)))};
\end{axis}
\end{tikzpicture}
\end{document}

enter image description here

I needed to modify completely the (log y) domain to see something of the red curve.

Ah sorry I forgot a log(10) in the domain bounds. Will fix.


Here is with correct domain bounds after using ln. Apparently I could not use directly ln(10) in the specs for these, so I used coarse approximation.

\documentclass{article}
\usepackage{pgfplots}
%\usetikzlibrary {spy}
%\usetikzlibrary{fpu}
\begin{document}
\begin{tikzpicture}
\begin{axis}[xlabel=$\log T$,ylabel=$\log \sigma$,xmin=-6.9, xmax=4.6, ymin=-2.3, ymax=41.45,restrict y to domain=-2.3:41.45]
\addplot [black,thick,domain=-6.9:4.6, y domain=-2.3:41.45,restrict y to domain=-2.3:41.45,
samples=200]{x + 40*exp(-x) + ln(1 - exp(-10*exp(-x)))};
\addplot[red,thick,domain=-6.9:4.6, y domain=-2.3:41.45,restrict y to domain=-2.3:41.45,
samples=400]{x + 120*exp(-x) + ln(1 - exp(-10*exp(-x)))};
\end{axis}
\end{tikzpicture}
\end{document}

Of course \log in the labels is to refer to natural logarithm, not base 10 logarithm.

enter image description here

0

You try to compute too big values

I think that you are trying to compute a huge number with exp(12*10/x) when x=1e-3. Even for x=1e-2, I can't compute the output with Python and numpy. I suggest changing the x range (to 1:1e3 for example if it fits your needs) or computing the log values (if it's okay for your application) with an other tool (python and matplotlib2tikz for example) and plot the coordinates with pgf.

It seems that your maximum value on y is reached for the second function for x around 2.96, so I'd recommend changing the x range over the two solutions.

  • how's this an answer? reads more like a comment, IMHO. – naphaneal Apr 26 '18 at 9:50
  • @naphaneal what do you mean? that may be an answer. Actually I am going to post a similar one. – user4686 Apr 26 '18 at 9:51
  • @jfbu I see a lot of "I <action>" messages and assumptions inside the post, I find it lacks in a real attempt on answering why stuff happens. that's what I think. I'm maybe wrong, which does happen well enough. – naphaneal Apr 26 '18 at 10:23

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.