# Speeding up this NIntegrate

I'm trying out the code below and it takes quite a long time to compute and throws eincr and slwcon warnings. Is there a way to speed this up?

phase[u_, m_, \[Theta]_, \[Phi]_] :=
u^3 + 2 m \[Theta] (3/(4 m))^(2/3) Cos[\[Phi]] u^2 +
m \[Theta]^2 (3/(4 m))^(1/3) u - m \[Theta] Cos[\[Phi]];

integrand[u_,
m_, \[Theta]_, \[Phi]_] := (-2 (3/(4 m))^(1/3)
u + \[Theta] ) Exp[-I phase[u, m, \[Theta], \[Phi]]];

integral[\[Theta]_, \[Phi]_, m_, {ulo_, uhi_}] :=
NIntegrate[integrand[u, m, \[Theta], \[Phi]], {u, ulo, uhi},
MaxRecursion -> 20, WorkingPrecision -> 20] //
Timing

integraltab =
Monitor[Table[{\[Theta], \[Phi],
integral[\[Theta], \[Phi], 100, {-Infinity, Infinity}]}, {\[Theta], 0,
Pi, Pi/32}, {\[Phi], 0, 2 Pi,
2 Pi/63}], {\[Theta], \[Phi]}];

• Do all 2000+ integrals have the same problem? Or can you narrow down the problem to test case one could start with? – Michael E2 Aug 20 '20 at 13:13
• @MichaelE2 For the first couple of values of theta, it's fairly fast. After that, it's really slow. – 123infinity Aug 20 '20 at 14:06

The integrand only depends on  Cos[\[Phi], that's why you can decrease the integration range to {\[Phi], 0, Pi} (- 50% evaluation time!)!

Include the option Method -> {Automatic, "SymbolicProcessing" -> 0} inside NIntegrate:

integral[\[Theta]_, \[Phi]_, m_, {ulo_, uhi_}] :=
NIntegrate[integrand[u, m, \[Theta], \[Phi]], {u, ulo, uhi} ,MaxRecursion -> 20, WorkingPrecision -> 20
,Method -> {Automatic, "SymbolicProcessing" -> 0}]


the grid of 101x101 tablevalues is evaluated in nearly 75s!

integraltab = Monitor[Table[{\[Theta], \[Phi],integral[\[Theta], \[Phi],100, {-Infinity, Infinity}]}
, {\[Theta], 0, Pi,Pi/10}, {\[Phi], 0,  Pi, Pi/10}], {\[Theta], \[Phi]}]; // Timing
(*{74.7813, Null}*)


Without these modifictions the evaluation of 101x101 grid lasts around 1700s ( speedup factor 23 ) !

Hope it helps!

• Thank you, but I actually need it over 2 Pi since I'll later integrate this over a sphere. – 123infinity Aug 21 '20 at 14:20
• No problem, because Cos[2Pi-phi]==Cos[Phi]. – Ulrich Neumann Aug 21 '20 at 14:53
• … Without this symmetrie evaluation time still would be 12times faster! – Ulrich Neumann Aug 21 '20 at 14:56