As always there are several ways to improve the speed
- Options Use MaxRecursions and MaxPoints
- Method Try using different methods to obtain quickest solution.
- Precalculate Use Block or Module to have some intermediate results only calculated once when required.
- Analyze Very general advice: use debug features as AbsoluteTiming at several places to see, where time is lost.
- Read Read stackexchange and find answers like: Methods to speed up numerical NDSolve, NIntegrate,
In your case I could improve speed by using
Method -> {Automatic, "SymbolicProcessing" -> 0}
and by controlling MaxRecursions. How few recursions you use depends on how exact you need to have the results:
aA[g_?NumberQ, b_?NumberQ, i_] := Pi - 2 b g NIntegrate[
1/Sqrt[g^2 - b^2*g^2 y^2 - 4*y^12 + 4 y^6], {y, 0,
minroot[g, b] - 0.00001}, MaxRecursion -> i, Method -> {Automatic, "SymbolicProcessing" -> 0}];
qQ[g_?NumberQ, i_] := NIntegrate[2*(1 - Cos[aA[g, b, i]]) b, {b, 0, 10}, MaxRecursion -> i, Method -> {Automatic, "SymbolicProcessing" -> 0}];
Lets see, what i we need:
Table[qQ[5, i] // Timing, {i, 1, 6}]
{{0.076005, 0.983541}, {0.116007, 0.854045}, {0.176011, 0.807208}, {0.176011, 0.782326}, {0.552034, 0.762594}, {0.632040, 0.762594}}
Looks like 6 is enough. Then:
o[T_, i_, j_] := (1/T^3) NIntegrate[(g^5*qQ[g, i])/E^(g^2/T), {g, 0, 50},
MaxRecursion -> j, Method -> {Automatic, "SymbolicProcessing" -> 0}];
And we see that
Table[o[5, 6, j] // Timing, {j, 1, 3}]
{{25.529596, 0.871541}, {40.394524, 0.868401}, {53.767361, 0.868459}}
j=1 is sufficient and calculation takes 26 seconds!
Kinda hacky, but it is very important to keep in mind how exact you really need the results.
Solve
outside ofminroot
! $\endgroup$NSolve
(keeping it in the loop) might help slightly. $\endgroup$ParallelTable
maybe. Check documntation on parallel operations in Mathematica. $\endgroup$