# NIntegrate::inumri error with continuous function

I'm trying to calculate the finite part of a divergent integral numerically, but as I bring the regulator down to $0$, Mathematica starts throwing an error.

ν = 1/3;
α = 1/100;
z = 1;
ϵ = 1/200000000000000;
NIntegrate[
BesselK[1, Sqrt[(x^2 + z^2)]]/
Sqrt[(x^2 + z^2)] x (Cosh[(1 - ϵ) x]),
{x, 0, ∞},
MaxRecursion -> 20, WorkingPrecision -> 40
]


NIntegrate::inumri: "The integrand (x\BesselK[1,Sqrt[1+x^2]]\Cosh[(199999999999999 x)/200000000000000])/Sqrt[1+x^2] has evaluated to Overflow, Indeterminate, or Infinity for all sampling points in the region with boundaries {{0.*10^-20,3.6700530551513758066*10^28}}."

I fully expect the answer to get arbitrarily large and I will have to subtract a counterbalancing large number (which I've already calculated) so the precision may be bad, but I don't understand where this error is coming from.

Why am I getting this error for a smooth function?

It's from the Bessel factor:

Cosh[(1 - ϵ) x] /. x -> 10.40^16


Note that the Bessel function evaluates to Underflow[]:

• I see, so as the exponential decay gets slower and slower, NIntegrate is looking at larger and larger 'x' values, and at some point the exponential increase/decrease just gets too ridiculous to be calculated. The fact that the error message says for ALL points in the region misled me. – Kevin Driscoll May 20 '16 at 1:16
• It sounds then like one solution is to integrate the full function up to some large but manageable 'x' value and then do the rest semi-analytically so that I can cancel the dueling exponentials by hand. I kind of figured NIntegrate would be smart enough to figure out what was going on and do this automatically, but then again I haven't though about corner cases or anything. – Kevin Driscoll May 20 '16 at 1:21
• @KevinDriscoll When considering the ALL, consider that the smallest sample point is probably about 1/20 of 10^28. -- Yeah, probably some sort of manual intervention like you suggest will be necessary. – Michael E2 May 20 '16 at 2:11

We can learn something by looking at the progression of finite integrals:

z = 1;
\[Epsilon] = 1/200000000000000;
trend = Table[{n,
NIntegrate[
BesselK[1, Sqrt[(x^2 + z^2)]]/
Sqrt[(x^2 + z^2)] x (Cosh[(1 - \[Epsilon]) x]), {x, 0, n},
MaxRecursion -> 20, WorkingPrecision -> 40] }, {n, 10^Range[7]}];

Show[{ListLogLogPlot[trend], LogLogPlot[ 5 /4 Sqrt[n] , {n, 1, 10^8}]}]


The fit here is just by observation / trial and error, but we can infer the integrand looks like 5/(8 Sqrt[x]) for large x. (I didn't get anywhere trying to prove that however )

By the way, I think were it not for the overflow error, NIntegrate would just tell you it diverges. (Same as you get with NIntegrate[1/Sqrt[x],{x,1,Infinity}]`

• For $\epsilon x < 1$ then your discussion in correct. But, for $\epsilon > 0$, eventually the integrand decreases exponentially, so the integral is convergent. Of course as $\epsilon \to 0$ it diverges, and you have to subtract out that divergent piece to get the finite part. – Kevin Driscoll May 22 '16 at 23:18