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


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

## Related Questions

### Single expression containing the same pattern multiple times

2  Asked on July 9, 2021

### How to get While to Return a Custom Value?

1  Asked on July 9, 2021 by user78013

### Manipulate mapping on lists

1  Asked on July 9, 2021

### How to align a network graph to an image?

1  Asked on July 9, 2021

### Vectorization of a function

2  Asked on July 9, 2021

### Eliminate a variable within an integral

1  Asked on July 9, 2021

### concept of tangent and residual in AceFem and automation

0  Asked on July 9, 2021

### Contour plot a 2d array

2  Asked on July 8, 2021

### Analytic continuation of the prime zeta function

0  Asked on July 8, 2021

### Equations in text cell in wrong format

0  Asked on July 8, 2021

### FEM: elastic cylinder under circumferential pressure

1  Asked on July 8, 2021

### Control the display unit length of PlotRange

1  Asked on July 8, 2021

### Most convenient way to set legend marker size?

2  Asked on July 8, 2021

1  Asked on July 8, 2021

### center of mass of a 2D square

2  Asked on July 8, 2021 by user77740

### New Compiler Technology in V12

1  Asked on July 7, 2021

### Applying Operators inside complex expressions to argument with Through

1  Asked on July 7, 2021

### Why is the convergent product with GoldenRatio evaluated as ComplexInfinity?

0  Asked on July 7, 2021

### Mathematica doesn’t simplify even providing the assumption

1  Asked on July 7, 2021

### How to drag an overlay image over the reference image?

2  Asked on July 7, 2021