# Numerical and analytical result for integral?

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

## 1 Answer

Why not choose a contour that avoids the pole?

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


-3.34504 + 0.523599 I

• This is pure genius! I'd give +10 if I could. – Kagaratsch Jun 5 '17 at 3:41