# NIntegrate for integrant with an obvious singularity

I know there are lots of posts like this one, but there is no hope for me to adopt any other experiences since the task seems to be very specific, at least from my level of understanding.

I have to integrate the function:

t = 0.2; w = 1; a = 4/w^2;

XX[lf_, mf_, l_, mg_, p_] := Abs[YY[lf, mf, l, mg, p]]^2;
YY[lf_, mf_, l_, mg_, p_] :=WignerD[{lf, mf, l}, t] Exp[-((a r^2)/4)] Sum[((Abs[mg - l] + p)!/((p - j)! (Abs[mg - l] + j)! j!)) (Sqrt/w)^(2 j + mg - l) (2/a)^(2 j + mg - l + 1) (Gamma[.5 (Abs[mg - mf] + mg - l + 2 + 2 j)]/(r Gamma[Abs[mg - mf] + 1])) a^(0.5 (2 j + mg - l + 1)) ((a r^2)/2)^(1/2 Abs[mg - mf] + .5)Hypergeometric1F1[( Abs[mg - mf] - 2 j - mg + l)/2, Abs[mg - mf] + 1, (a r^2)/4], {j, 0, p}];
MLG[lf_, l_, mg_, p_] := Sum[XX[lf, ii, l, mg, p], {ii, -lf, lf, 1}];
Res1 = (MLG[2, 1, 3, 0] - MLG[2, -1, 1, 0])/(MLG[2, 1, 3, 0] + MLG[2, -1, 1, 0]);

NIntegrate[Res1, {r, 0, 1000}, MaxPoints -> 500000, PrecisionGoal -> 10, MaxRecursion -> 50, WorkingPrecision -> 10]


I get the following message which is, unfortunately, not surprising.

If I plot the function, I do see the singularity close to zero and diverging behavior at big $r$ But maybe there is still a way to evaluate this. If not directly, maybe someone can suggest tricks...

I tried to use FullSimplify and Rationalize to make it nicer, but the expression is so complicated that the calculation takes forever.

• NIntegrate[Simplify[Res1, 0<r<1000], {r,0.01,1000}, MaxPoints->500000, PrecisionGoal->10, MaxRecursion->50, WorkingPrecision->10] completes almost instantly with a result 999.9900000 but Plot[Simplify[Res1, 0<r<1000], {r,.01,1000}, WorkingPrecision->32, PlotRange->All] seems to indicate the answer should be much closer to 317.9. Even NIntegrate[Simplify[Res1, 0<r<1000], {r,0.01,1000}] quickly yields 689.639 with a couple of warnings – Bill Dec 2 '16 at 3:59
• Changing approximate numbers to exact ones (2/10 for 0.2, 1/2 for 0.5) throughout, then NIntegrate[Res1, {r, 0, 1000}, PrecisionGoal -> 8, WorkingPrecision -> 50] works. That suggests there's too much rounding error in your integrand. – Michael E2 Aug 20 '17 at 17:34

t=0.2;w=1;a=4/w^2;