This question is a follow-up to my previous question.
The code I use at the moment is the following:
Bose[k_, μ_, nx_, ny_] := 1/(Exp[( k (nx + ny + 1) - μ)] - 1)
wavefunc[x_, n_] := 1/Sqrt[2^n Factorial[n] π] Exp[-x^2/2] HermiteH[n, x]
Intensity[k_, x_, y_, μ_, nmax_] := Sum[Bose[k, μ, nx, ny] (wavefunc[x, nx]*wavefunc[y, ny])^2, {nx, 0, nmax}, {ny, 0, nmax}]
Using this, I can now easily make plots with the following line (which was a suggestion in the answer to the previous question)
(pt1 = With[{expr = Intensity[Ω, x, 0, μ1, nmax]},
Plot[expr, WorkingPrecision -> 50, {x, -40, 40}];)
Show[pt1]
This sums up $500^2$ terms in about 4 minutes if I take a large working precision. (Typical values are $\Omega = 1/150$ and $\mu = 1/2 * \Omega$).
However, I would like to export the graph as data points in a .dat file, such that I can use the data elsewhere. This again suffers from extremely long running times. The code I use is
linearmesh[a_, b_, n_Integer] := Array[# &, n, {a, b}]
xarr = linearmesh[-40, 40, 160];
soly1 = Monitor[Table[Intensity[Ω, xarr[[i]], 0, μ, 150], {i, 1,Ngrid}], i];
Export["fit.dat", soly1]
but even for 150 terms this takes forever. Is there an easy way to speed this up significantly?
μ
andΩ
andnmax
into the code rather than state in the text of your question. Also, you forgot to add the definition ofNgrid
(though it's not hard to guess that it's160
.) Finally, your code cotains typo, theWith
inpt1
loses its right bracket, and the position ofWorkingPrecision
option is wrong. $\endgroup$