       Re: Oh, those complex values!!!

• To: mathgroup at smc.vnet.net
• Subject: [mg72206] Re: Oh, those complex values!!!
• From: "David W. Cantrell" <DWCantrell at sigmaxi.net>
• Date: Thu, 14 Dec 2006 05:49:31 -0500 (EST)
• References: <elja1i\$76b\$1@smc.vnet.net>

```aaronfude at gmail.com wrote:
> Integrating a real function, getting complex values again. How to get

Sorry I don't have time for a detailed answer, but maybe this will help.

> How to systematically avoid this pitfall?
>
> f=x Log[a+b x+Sqrt[c+2d x+x^2]];
> t = Assuming[c>d^2&&a>0&&b>0,Integrate[f, x]];
> u=t/.a\[Rule]2/.b\[Rule]2/.c\[Rule]10/.d\[Rule]1;
>
> N[u/.x\[Rule]1-u/.x\[Rule]0]
> 9.50705\[InvisibleSpace]-29.7626 \[ImaginaryI]

I don't know what you did above, but surely it's not what you intended.
Note the parentheses below.

In:= N[(u /. x -> 1) - (u /. x -> 0)]

Out= 0.954442 + 6.28319 I

The real part is correct, and the imaginary part is exactly 2 Pi:

In:= FullSimplify[Im[(u /. x -> 1) - (u /. x -> 0)]]

Out= 2 Pi

which I suppose is due to some branch cut. Anyway, we don't want that, so
to get what you want from (u /. x -> 1) - (u /. x -> 0), you could either
just subtract 2 Pi I from it or take its real part:

In:= FullSimplify[Re[(u /. x -> 1) - (u /. x -> 0)]]

Out=
(1/4)*(1 + 4*Sqrt*ArcCoth[Sqrt] - 4*Log + 4*Log - 12*Log[1 +
Sqrt] + 12*Log[2 + Sqrt] + 2*Log[4 + Sqrt] + 2*(2 + Sqrt)*
Log[(18*(5 + 3*Sqrt))/(9 - Sqrt + 2*Sqrt)] +
2*(-2 + Sqrt)*Log[(18*(-5 + 3*Sqrt))/(9 + Sqrt + 2*Sqrt)] +
2*(2 + Sqrt)*Log[(1/18)*(7 - 4*Sqrt)*(9 - 2*Sqrt + 2*Sqrt)]
+ 2*(-2 + Sqrt)*Log[(1/18)*(7 + 4*Sqrt)*(9 + 2*Sqrt +
2*Sqrt)] - 4*Sqrt*Re[ArcTanh[2/Sqrt]])

In:= N[%]

Out= 0.954442

David W. Cantrell

> NIntegrate[f/.a\[Rule]2/.b\[Rule]2/.c\[Rule]10/.d\[Rule]1, {x, 0, 1}]
> 0.954442
>