I would like to make an intensity plot of Bosons in a harmonic trapping potential. Hence, I would like to execute the following double summation (everything made dimensionless) for as many terms as possible
wavefunc[x_, n_] :=
1/(Sqrt[2^n Factorial[n] Sqrt[π]]) Exp[-x^2/2] HermiteH[n, x]
Intensity[x_, y_, μ_, nxmax_, nymax_] := Sum[(1/(Exp[((nx + ny + 1)/25 - μ)] - 1))
(wavefunc[x, nx]* wavefunc[y, ny])^2, {nx, 0, nxmax}, {ny, 0, nymax}]
Subsequently I would like to plot as follows
Plot[Intensity[x, 0, -1/5, 75, 75], {x, -15, 15}].
Note that the factor of 1/25 in the intensity expression above is related to a certain value of the temperature. A typical value for $\mu$ would be $-1/5$. However, if I take $n_{x_{max}} = n_{y_{max}} = 75$, this already takes a very long time. I am aware that the number of terms goes as $O(n^2)$. Still, I would be very happy if there would be some way to speed this up in Mathematica by some option of some sort, as I only expect full convergence for $n_{x_{max}}$ a multiple of 25.
wavefunc
$\endgroup$Intensity
is defined usingSetDelayed
, which forcesPlot
to evaluate the sum for every single choice ofx
value. Do insteadWith[{plt = Intensity[x, 0, -1/5, 75, 75]}, Plot[plt, {x, -15, 15}]]
. $\endgroup$Intensity
spits out, there are some HUGE numbers appearing. It's not wonder that there are numerical issues. Anyway, your question was about speed-up, which theWith
solution (or one of @MarcoB's solutions below) fixes. $\endgroup$