4

Consider the following integrand

integrand = (Cos[q] Sin[q])/((Cos[q]^2-10^-10 (6-2 Sin[q])^2+I 10^-20) (Sin[q]-4));

I would like to integrate this over 0 < q < π/2:

res = Integrate[integrand, {q, 0, π/2}];

The exact result is approximately equal to:

N[res, 30]

enter image description here

Now, if I try to compute the same integral numerically, the result deviates and has a rather big error:

N[
  {
    NIntegrate[integrand, {q, 0, π/2}, 
    WorkingPrecision -> 100, 
    AccuracyGoal -> Infinity, 
    Method -> "DoubleExponentialOscillatory", 
    IntegrationMonitor :> ((errors = Through[#1@"Error"]) &)]
  , 
    Total@errors
  }
, 30] // Quiet

enter image description here

I tried all available Methods, and various MinRecursion and MaxRecursion options. Nothing seems to improve the numerics. Is there a way to calculate this integral purely numerically to get agreement with exact integration at least for a couple first digits? (My actual integrals I need to calculate are similar but do not have such nice coefficients, so that exact routine never finishes calculation.)

J. M.'s missing motivation
  • 124,525
  • 11
  • 401
  • 574
Kagaratsch
  • 11,955
  • 4
  • 25
  • 72

1 Answers1

8

Why not choose a contour that avoids the pole?

NIntegrate[integrand,{q, 0, -I, -I+Pi/2,Pi/2}]

-3.34504 + 0.523599 I

Carl Woll
  • 130,679
  • 6
  • 243
  • 355