# Plotting a sum does not display anything

I have run into a problem with plotting a sum.

The background is calculating the occupation number of bosons in a one dimensional box.

$\qquad f_{BE}(E_i)=\frac{g_i}{\exp\left(\frac{E_i-\mu}{k_B T}\right)-1}$

with the energy $E_i$ of the state $i$, its degeneracy $g_i$, the chemical potential $\mu$, Boltzmann´s constant $k_B$ and the temperature $T$.

For the one dimensional case we have $g_i=1$ and $E_i=ni^2$ (where I set the level spacing equal to 1). $ni$ is a natural number running from $0$ to $nmax$.

I also want to scale some variables; i.e., I set $\frac{\mu}{k_B T}\rightarrow mu$ and $k_B T\rightarrow t$

fBE[ni_, mu_, t_] := 1/(Exp[ni^2/t - mu] - 1)
nmax = 100;
n[mu_, t_] := Sum[fBE[ni, mu, t], {ni, 0, nmax}];
Plot[n[mu, 10], {mu, -10., -0.001}]


For bosons the (scaled) chemical potential has to be negative because of physical reasons. Sometimes things diverge for $\mu\rightarrow 0$ therfore I just plot from $[-10,-0.001]$. The plot however results in an empty plot for values of $t$ smaller than 15.

But when I make a list with {mu, n[mu, t]} (for a given t) and use ListPlot I get a plot.

nList = Table[{mu, n[mu, 10]}, {mu, -10, -0.001, 0.01}];
ListPlot[nList]


So why can´t I just use plot? Am I missing something?

• Put a semicolon after the definition of fBE and it plots OK. Commented May 8, 2017 at 20:52
• Would you edit your post to add a bit at the end, This <code> doesn't Plot and this <slightly changed code> does Plot so that the reader can scrape-n-paste each and see exactly what you are seeing?
– Bill
Commented May 8, 2017 at 20:54
• I can duplicate your problem on my system. See the answer I posted below. Commented May 9, 2017 at 0:17
• @bill s : This somehow doesn´t work for me.
– ctrl
Commented May 9, 2017 at 18:52
• Using exactly the code in grey that you have above, in V10.1 if I evaluate your first three lines of code and then evaluate in either order the Plot or the the two lines for ListPlot I see a well formed graph for each of them, but the ListPlot has a few more scruffy dots.
– Bill
Commented May 10, 2017 at 5:50

It looks to me to be a bug in Plot when nmax gets large. On my system (V11.0.1 running on OS X 10.10.2) "large" means nmax = 85. I suspect Plot is getting into some numerics difficulty.

It is easy to demonstrate the problem by making nmax an argument to n.

fBE[ni_, mu_, t_] := 1/(Exp[ni^2/t - mu] - 1)
n[mu_, t_, nmax_] := Sum[fBE[ni, mu, t], {ni, 0, nmax}]

Plot[n[mu, 10., 84], {mu, -2, -1}]


Plot[n[mu, 10., 85], {mu, -2, -1}]


Note: You really don't need to sum to anything like 100 to make a plot. I made one with nmax = 20 and got a quite decent plot.

 Plot[n[mu, 10., 20], {mu, -10, -.1}, PlotRange -> All]


• Thank you for your answer, I´m glad that someone else also experiences this problem. Unfortunately in the future I would like to perform quantitative calculations with reasonable values where $N_{max}$ is much bigger than 80. But I guess I then have to use the ListPlot version for visualization.
– ctrl
Commented May 9, 2017 at 18:48