# Convergence in NIntegrate vs Integrate

I am faced with this situation that for a certain integration, $\int _0 ^\infty \frac { \tanh (\pi \sqrt{x} )} {\sqrt{x+10} } dx$ - the command Integrate returns that this doesn't converge but NIntegrate gives back a number - but after some messages about slow convergence and precision etc.

What exactly is going on? What is the "right" answer?

-

Every integral over a function behaving asymptotically (when $x$ goes to infinity) as $\frac{1}{x^\alpha}$ where $\alpha \leq1$ is divergent, it's a mathematical theorem which could be found in every reasonable handbook of calculus.
Since Tanh[ π Sqrt[x]] goes to one rapidly we find that the integral is indeed divergent.
We can demonstrate this fact with the function at hand in many ways, let's provide two of them.

## 2. estimating $\int _0 ^a \frac { \tanh (\pi \sqrt{x} )} {\sqrt{x+10} } dx$

The integral can be easily bounded by a diverging sum

SumConvergence[ Tanh[ π Sqrt[x]]/Sqrt[x + 10], x]

 False

Plot[ Tanh[ π Sqrt[#]]/Sqrt[# + 10]& /@ {x, IntegerPart[x + 1] - 1, 1 + IntegerPart[x]},
{x, 0, 12},
PlotRange -> {0.2, 0.31}, AxesOrigin -> {0, 0}, Filling -> {1 -> {2}},
FillingStyle -> Darker @ Cyan, Evaluated -> True, Exclusions -> None,
PlotStyle -> Thick]


Let's consider a simple function 1/ Sqrt[x + 11]:

Resolve[
ForAll[x, x > 1, Tanh[ π Sqrt[x]]/Sqrt[x + 10] > 1/ Sqrt[x + 11]], x, Reals]

True

Integrate[ 1/Sqrt[x + 11], {x, 0, a}, Assumptions -> a > 0]

Limit[ %, a -> ∞]

-2 Sqrt[11] + 2 Sqrt[11 + a]

∞


Moreover defining

f[a_?NumericQ] := NIntegrate[ Tanh[ π Sqrt[x]]/Sqrt[x + 10], {x, 0, a}] -
NIntegrate[ 1/Sqrt[x + 11], {x, 0, a}]


we find that

FindRoot[ f[a], {a, 2}]

{a -> 2.02636}


thus for a > 2.02636 NIntegrate[ Tanh[ π Sqrt[x]]/Sqrt[x + 10], {x, 0, a}] exceeds NIntegrate[ 1/Sqrt[x + 11], {x, 0, a}]

Plot[{ Tanh[  π Sqrt[x]]/Sqrt[x + 10], 1/ Sqrt[x + 11]}, {x, 0, 15},
PlotRange -> {0, 0.33}, PlotStyle -> Thick, Evaluated -> True,
Filling -> {1 -> {2}}, PlotLegends -> "Expressions"]


We found a simpler function with an integral smaller for an every finite parameter a > 3 which is clearly divergent, so the original function is divergent as well when a tends to infinity.

On the other hand NIntegrate returns a well defined approximation with another asymptotic behaviour, this integrand Tanh[ π Sqrt[x]]/(1 + x)^c for every c > 1 provides a convergent integral, e.g.:

NIntegrate[ Tanh[ π Sqrt[x]]/(1 + x)^(5/4), {x, 0, ∞}]

3.92916


while Integrate is unable to provide an exact symbolic result.

The reason that Mathematica does return some number is that NIntegrate might be even better, however it returns quite clear warning:

NIntegrate[ Tanh[ π Sqrt[x]]/Sqrt[x + 10], {x, 0, ∞}]

NIntegrate::slwcon: Numerical integration converging too slowly;
suspect one of the following: singularity, value of the integration is 0,
highly oscillatory integrand, or WorkingPrecision too small. >>

NIntegrate::ncvb: NIntegrate failed to converge to prescribed accuracy after
9 recursive bisections in x near {x} = {8.16907*10^224}. NIntegrate obtained
3.84394179620275415.954589770191005*^13977
and 3.84394179620275415.954589770191005*^13977 for the integral and error estimates. >>

3.843941796202754*10^13977


Therefore one shouldn't be misled with that number. Integrate works fine yielding an unevaluated input:

Integrate[ Tanh[ π Sqrt[x]]/Sqrt[x + 10], {x, 0, ∞}]

Integrate::idiv:
Integral of Tanh[ π Sqrt[x]]/Sqrt[10+x] does not converge on {0, ∞}. >>

Integrate[ Tanh[ π Sqrt[x]]/Sqrt[x + 10], {x, 0, ∞}]

-
I think you mean \alpha>-1? – Daniel Lichtblau Mar 10 '14 at 19:51
No I meant that $\int_b^\infty \frac{d x}{x^\alpha}$ is divergent for $\alpha \leq 1$ and $b > 0$. – Artes Mar 10 '14 at 20:45
Ah, yes, was forgetting you had it in a denominator. – Daniel Lichtblau Mar 10 '14 at 22:02