4
$\begingroup$

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.)

$\endgroup$

1 Answer 1

8
$\begingroup$

Why not choose a contour that avoids the pole?

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

-3.34504 + 0.523599 I

$\endgroup$
1
  • $\begingroup$ This is pure genius! I'd give +10 if I could. $\endgroup$
    – Kagaratsch
    Jun 5, 2017 at 3:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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