3
$\begingroup$

I'm trying to evaluate

NIntegrate[Sin[x] Exp[I m (x + Cos[x] + Sin[x])], {x, 1, 100}]

with m=1000. The problem is that it's highly oscillatory. What would be the best method to do this integral?

$\endgroup$
  • $\begingroup$ Add this:Method -> "LocalAdaptive", MaxRecursion -> 100 to NIntegrate. $\endgroup$ – Mariusz Iwaniuk May 23 at 14:51
  • $\begingroup$ @MariuszIwaniuk This is still giving me errors for some reason. $\endgroup$ – 123infinity May 23 at 14:59
  • $\begingroup$ I use Mathematica 12.1 and for me works fine. $\endgroup$ – Mariusz Iwaniuk May 23 at 15:02
6
$\begingroup$

This works fast and no warnings

ClearAll[x, m];
m = 100;
NIntegrate[Sin[x] Exp[I m (x + Cos[x] + Sin[x])], {x, 1, 100}, MinRecursion -> 3]

Mathematica graphics

(actually MinRecursion -> 2 works also, as well as 1. but 3 looks more cool since it is odd number.)

| improve this answer | |
$\endgroup$
  • $\begingroup$ This worked! Thank you so much! $\endgroup$ – 123infinity May 23 at 14:59
4
$\begingroup$

If m is an integer, then the integrand is periodic and the trapezoidal rule is a good way to go, except for the leftover bit when the length of the interval is not an exact multiple of the period.

i1 = Block[{m = 1000},
   NIntegrate[Sin[x] Exp[I m (x + Cos[x] + Sin[x])],
    {x, 1, 1 + 2 Pi},   (* any period will do *)
    Method -> "Trapezoidal",
    MaxRecursion -> Round[1 + 1.31 Log[m]]] (* theoretically O[Log[m]] *)
   ];

periods = Round[(100 - 1)/(2 Pi)];

i2 = Block[{m = 1000},
   NIntegrate[
    Sin[x] Exp[I m (x + Cos[x] + Sin[x])],
    {x, 1 + periods*2 Pi, 100},
    Method -> {
      "GaussKronrodRule",
      "Points" -> 41}] (* more recursion or more points for larger m *)
   ];

periods*i1 + i2
(*  1.24527 + 0.239249 I  *)
| improve this answer | |
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.