# Why does this happen?

Discussion in 'Mathematica' started by Budaoy, Jul 6, 2007.

1. ### BudaoyGuest

I have a problem in calculating this integral shown below:

Integrate[Log[1+Exp[x]/Sqrt[x]],{x,0,Infinity}]
Pi^2/6

N[%]
1.64493

NIntegrate[Log[1+Exp[x]/Sqrt[x]],{x,0,Infinity}]
1.01799

Where does this difference come from and which one is correct?

Budaoy, Jul 6, 2007

2. ### Jean-Marc GullietGuest

How did you get these results? On what platform are you working?

(* Mathematica 6.0 -- Similar messages with 5.2 *)

In:= Integrate[Log[1 + Exp[x]/Sqrt[x]], {x, 0, Infinity}]

During evaluation of In:= Integrate::idiv: Integral of Log[1+\
\[ExponentialE]^x/Sqrt[x]] does not converge on {0,\[Infinity]}. >>

Out= Integrate[Log[1 + E^x/Sqrt[x]], {x, 0, Infinity}]

In:= NIntegrate[Log[1 + Exp[x]/Sqrt[x]], {x, 0, Infinity}]

During evaluation of In:= NIntegrate::inumri: The integrand Log[1+\
\[ExponentialE]^x/Sqrt[x]] has evaluated to Overflow, Indeterminate, \
or Infinity for all sampling points in the region with boundaries \
{{0.,4.64782*10^14}}.

Out= NIntegrate[Log[1 + E^x/Sqrt[x]], {x, 0, Infinity}]

Regards,
Jean-Marc

Jean-Marc Gulliet, Jul 7, 2007

3. ### dimitrisGuest

Budaoy :
First of all you should tell us WHAT version you use.

In 5.2 you get

In:=
Integrate[Log[1+Exp[x]/Sqrt[x]],{x,0,Infinity}]

\!$$\* RowBox[{\(Integrate::"idiv "$$, $$\ $$$$\$$\), "\"\<Integral of Log[1 +
E^x/Sqrt[x]] does not converge on {0, }. \!$$\*ButtonBox[\(More...$$,
ButtonData:>\\\"Integrate::idiv\\\",
ButtonFrame->\\\"None\\\"]\)\>\""}]\)

Out=
Integrate[Log[1 + E^x/Sqrt[x]], {x, 0, Infinity}]

which is correct.

In another CAS I use, I also took

convert("Integrate[Log[1 + Exp[x]/Sqrt[x]], {x, 0, Infinity}]
",FromMma);value(%);

infinity
/
| exp(x)
| ln(1 + -------) dx
| sqrt(x)
/
0
infinity

The problem arise from the behavior of the integrand at infinity.

Try

In:=
Series[Log[1 + Exp[x]/Sqrt[x]], {x, Infinity, 3}]
(*essential singularity messages are ommited*)
Out=
Log[E^x + SeriesData[x, Infinity, {1}, -1, 7, 2]] + SeriesData[x,
Infinity, {Log[x^(-1)]/2}, 0, 6, 2]

As regards numerical integration,

In:=
NIntegrate[Log[1+Exp[x]/Sqrt[x]],{x,0,Infinity},SingularityDepth-
\!$$\* RowBox[{\(NIntegrate::"ncvb"$$, $$\ $$$$\$$\), "\<\"NIntegrate
failed
to converge to prescribed accuracy
after \\!\$$7\$$ recursive bisections in \\!\$$x\$$ near \\!\$$x\$$ = \\!\
\$$255.`\$$. \\!\$$\\*ButtonBox[\\\"More...\\\", \ ButtonStyle->\\\"RefGuideLinkText\\\", ButtonFrame->None, \ ButtonData:>\\\"NIntegrate::ncvb\\\"]\$$\"\>"}]\)

Out=
7.022806219872675*^8

So, the conclusion is that the integral diverges.

If you want Mathematica's integrator to be more carefully
regarding convergence checking use the setting
GenerateConditions->True (at least from version 3 and up
to 5.2; I don't have version 6 to check it).

BTW,

I notice that in version 5.2 we have (*watch the minus sign in the
exponential*)

In:=
Integrate[Log[1 + Exp[-x]/Sqrt[x]], {x, 0, Infinity}]

Out=
Pi^2/6

In:=
N[%]

Out=
1.6449340668482262

In:=
NIntegrate[Log[1 + Exp[-x]/Sqrt[x]], {x, 0, Infinity}]

Out=
1.0179913870581465

I think that Vladimir Bondarenko discovered that this bug exists also
in version 6!
(in a thread in another forum).

Dimitris

dimitris, Jul 7, 2007
4. ### David ReissGuest

Perhaps you meant a different integral? The one you posted increases
monotonically positive as x->Infinity.

--David

David Reiss, Jul 7, 2007
5. ### David ReissGuest

Oops, my bad. I see that there was only a typo in your expression:
the Exp should have had a - sign in its argument:

Integrate[Log[1+Exp[-x]/Sqrt[x]],{x,0,Infinity}]

David Reiss, Jul 7, 2007
6. ### dhGuest

Hi Budaoy,

look at your integrand. For large x you can neglect 1 and get

Log[Exp[x]/Sqrt[x], but this is Log[Exp[x]]-Log[Sqrt[x]], where the

first part is mach larger than the second. Therefore the integrand is

approx.: x. This means, the integral does not exisit.

hope this helps, Daniel

dh, Jul 7, 2007
7. ### David ReissGuest

OK, since most folks didn't catch Budasoy's typo in the Exp. Here is
an "analysis" of the problem (Mathematica 6.01. There does appear to
be a numerical inconsisstency between the exact result and the
numerical one. Is this possibly due to the singularity of the
integrand at 0? Or perhaps we have a bug... 'tis not clear to me
before my morning coffee...

(M 6) In:= Integrate[Log[1 + Exp[-x]/Sqrt[x]], {x, 0, Infinity}]

(M 6) Out= \[Pi]^2/6

(M 6) In:= Limit[Log[1 + Exp[-x]/Sqrt[x]], x -> Infinity]

(M 6) Out= 0

(M 6) In:= Limit[Log[1 + Exp[-x]/Sqrt[x]], x -> 0]

(M 6) Out= \[Infinity]

(M 6) In:= N[\[Pi]^2/6]

(M 6) Out= 1.64493

(M 6) In:= Table[
NIntegrate[Log[1 + Exp[-x]/Sqrt[x]], {x, 10^-n, n 10}], {n, 1, 10}]

(M 6) Out= {0.837883, 0.989369, 1.01402, 1.01748, 1.01793, \
1.01798, 1.01799, 1.01799, 1.01799, 1.01799}

(M 6) In:= Integrate[Log[1 + Exp[-a x]/x^(1/n)], {x, 0, Infinity},
Assumptions -> {Re[1/n] < 1, a > 0}]

(M 6) Out= (n \[Pi]^2)/(12 a (-1 + n))

(M 6) In:= (n \[Pi]^2)/(12 a (-1 + n)) /. {n -> 2, a -> 1}

(M 6) Out= \[Pi]^2/6

(M 6) In:= quickanddirty[delta_] :=
Module[{data},

data = Table[
[email protected][1 + Exp[-x]/Sqrt[x]], {x, 10^-5, 10, delta}];

Tr[data delta]
];

(M 6) In:= quickanddirty[10^-2]

(M 6) Out= 1.05924

(M 6) In:= quickanddirty[10^-3]

(M 6) Out= 1.02151

(M 6) In:= quickanddirty[10^-4]

(M 6) Out= 1.01823

David Reiss, Jul 8, 2007
8. ### dimitrisGuest

David Reiss :
It is a bug in Integrate.
NIntegrate's result is correct!

Dimitris

dimitris, Jul 9, 2007
9. ### dreissGuest

yes indeed... hence my post....

dreiss, Jul 10, 2007