0

I'm trying to compute a fairly simple numerical integral, but it seems to take forever to compute:

f[s_, t_] :=  0.4714 *Exp[-0.6666*I *s + 0.3333*I*t] + 0.4714*Exp[-1.66666*I*s + 1.33333*I*t]
NIntegrate[f[s, t]^3, {s, 0, 2*Pi}, {t, 0, 2*Pi}]

If I remove the decimal places, to

f[s_, t_] :=  0.4 *Exp[-0.6*I *s + 0.3*I*t] + 0.4*Exp[-1.6*I*s + 1.3*I*t]
NIntegrate[f[s, t]^3, {s, 0, 2*Pi}, {t, 0, 2*Pi}]

then it computes in about a second (which still seems quite slow?). But howcome it takes so much longer for the first integral? I am missing something. Perhaps my pc is out of resources.

Bruce Bartlett
  • 455
  • 2
  • 7

1 Answers1

2
NIntegrate[f[s, t]^3, {s, 0, 2*Pi}, {t, 0, 2*Pi},Method -> "LocalAdaptive"]  
(*{0.0707075, 6.49829*10^-8 + 1.78683*10^-11 I}*)

evaluates immideatly.

By the way it is good praxis to use symbolic parameter values if possible:

f[s_, t_] :=0.4714*Exp[-2/3*I*s + 1/3*I*t] + 0.4714*Exp[-5/3*I*s + 4/3*I*t] //Rationalize[#, 0] &
NIntegrate[f[s, t]^3, {s, 0, 2*Pi}, {t, 0, 2*Pi},Method -> "LocalAdaptive"]  
(*-2.80592*10^-16 - 2.21828*10^-16 I*)

Integral equals (numerical) zero!

Integrate[f[s, t]^3, {s, 0, 2*Pi}, {t, 0, 2*Pi} ]
(* 0 *)
Ulrich Neumann
  • 53,729
  • 2
  • 23
  • 55
  • 1
    Thank you. Seems strange it doesn't try something like "LocalAdaptive" by default in this case. I don't know what it's doing but it feels like the default behaviour shouldn't struggle on this integral. – Bruce Bartlett Jun 20 '23 at 12:21
  • 1
    @BruceBartlett "I don't know what it's doing but it feels like the default behaviour shouldn't struggle on this integral." -- 1) Zero value integrals are simply not that important. 2) In order to see the strategy and rule selected by NIntegrate you can try following this answer. – Anton Antonov Jun 20 '23 at 15:48
  • 1
    Including the option AccuracyGoal -> Automatic also leads to a quick evaluation. – Michael Seifert Jun 20 '23 at 20:34
  • Many thanks for these tips. – Bruce Bartlett Jun 23 '23 at 07:54