TransWikia.com

Speeding up this NIntegrate

Mathematica Asked by 123infinity on December 20, 2020

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]}];

One Answer

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!

Answered by Ulrich Neumann on December 20, 2020

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP