# Fermi--Dirac in pgfplots, dimension too lage

I'm trying to draw a plot of the Fermi-Dirac distribution, for which I'd like to show a few lines of varied temperate (T). My code works for this, except for zero temperature, it results in a Dimension too large error from pgfplots. Is there a way to resolve this while keeping the real value of the Boltzman constant, k_B, in electron volts?

MWE:

\documentclass[tikz,border=5pt]{standalone}
\usepackage{pgfplots}

\begin{document}

\begin{tikzpicture}
\begin{axis}[
xlabel=$\frac{mv^2}{2k_BT}$ (eV),
ylabel=$f(n)$,
legend entries={0 K,100 K,1000 K,10000 K},
x tick style={color=black},
y tick style={color=black},
xtick pos=left,
ytick pos=left,
xmin=-3,
xmax=3,
ymin=-0.1,
ymax=1.1
]
\end{axis}
\end{tikzpicture}

\end{document}


This code compiles but 80.617e-5 should be 8.617e-5 which breaks the code. I've tried varying/removing xmin, xmax with no success. I also read in a few answers something to do with fpu but this didn't seem to work for me or is no longer required? restrict x to domain did not seem to help, though I could be using it wrong. • TeX does not really support floating point numbers. Tikz fakes it using dimen registers (fixed point) and converting everything into text. To do it right you should compute the numbers elsewhere and import them using plgplotstable. Jun 22, 2015 at 12:26

The root cause is a deficiency in the TeX based floating point unit employed by pgfplots. An intermediate result requires to compute

\begingroup
%\tracingmacros=2 \tracingcommands=2
\pgfkeys{/pgf/fpu}
\pgfmathparse{exp(-3.4814e4)}\pgfmathresult
\endgroup


which reaches some internal limit. I accept that as bug report and will see if I can fix it.

For the time being, you can consider to compile your example with

• pgfplots in version 1.12 or newer and
• lualatex .

This will work out of the box (as soon as you fix the syntax error in your first \addplot expression, there is a round brace too much in it).

• I must have added a set of parentheses when trying to get it to work. It works, as you said, with LuaLaTeX, pgfplots v1.12 and \addplot[samples=250,black] {1/(exp((x)/(8.617e-5))+1)}; I'll have to read up on how Lua handles the situation for my knowledge. Jun 23, 2015 at 7:35
• Ok, great. If I am not mistaken, there is a hidden question like "why does lua help here" behind your comment. If so, the answer would be: pgfplots comes with a partial reimplementation in lua and switches to lua whenever it can. See lua backend in the pgfplots reference manual for details pgfplots.sourceforge.net Jun 23, 2015 at 18:30