1
$\begingroup$

I've tried to solve the following integral, but I get a complex solution even tough it should only have a real part.

$$f(x)=- \frac{10^{-20} x}{0.99005- e^{10^{-12}x}}$$

Now I want to calculate the following:

$$\int_0 ^{10^9} f(x) dx$$

which shoud just give a real solution if we look at the graph

Plot of f(x)

But using the following code I get a complex solution:

Integrate[f[x], {x, 0, 10^9}]

Which gives the following solution.

$0.471182 - 6.29146\times10^{-13} i$

Can anyone explain to me why the solution has a complex part? I suppose I can neglect this part but I don't know why. Also I calculated the indefinite integral and I believe that part of the problem comes from the PolyLog:

Integrate[f[x], x] // Simplify

(* Out: 
  x (-5.05025 10^(-21) x + 1.01005*10^(-8) Log[1. - 1.01005 Exp[1. 10^(-12) x)]] + 
    10100.5 PolyLog[2., 1.01005 Exp[1. 10^(-12) x]]
*)
$\endgroup$
  • 1
    $\begingroup$ If you use NIntegrate, which you should since you have floating points in your definition of f, then it gives a real result $\endgroup$ – Jason B. May 25 '16 at 14:25
  • $\begingroup$ Yes using NIntegrate gives the same real result (so without the im part), but I still get the same problem when I use a symbolic function instead of floating points (which I would prefer since i need to change the numbers in my function) $\endgroup$ – DeanTheMachine May 25 '16 at 14:36
  • $\begingroup$ Please format inline code and code blocks by selecting the code and clicking the {} button above the edit window. It is recommended that you browse the Markdown help . Apply this to the function definition f. $\endgroup$ – Jack LaVigne May 25 '16 at 14:39
  • 1
    $\begingroup$ @JasonB Thanks for the hint; I didn't even recognize it $\endgroup$ – user36273 May 25 '16 at 16:39
  • $\begingroup$ @rewi it was tricky to differentiate the the font sizes in the TeX with a superscript on a superscript $\endgroup$ – Jason B. May 26 '16 at 5:32
2
$\begingroup$

Use higher precision

f[x_] = -(10^-20 x)/(0.99005 - E^(10^-12 x)) // Rationalize // Simplify;

int = Integrate[f[x], {x, 0, 10^9}] // FullSimplify;

int // N[#, 20] & // Chop[#, 10^-20] &

(*  0.47118211649097404645  *)
$\endgroup$
  • $\begingroup$ Can you explain how this code gives higher precision? Because as I see it you just replace numbers that are close to zero with zero $\endgroup$ – DeanTheMachine May 26 '16 at 12:01
  • $\begingroup$ @DeanTheMachine - The Chop[#, 10^-20] & only eliminates absolute values less than 10^-20. With machine precision the artifact was on the order of 10^-12. Increasing the precision with N[#, 30] & would further reduce the artifact. Since you can reduce the artifact to an arbitrarily small value, it is very strong evidence that the imaginary part is actually zero. $\endgroup$ – Bob Hanlon May 26 '16 at 15:11
1
$\begingroup$

First, if you use Integrate, you should define your function exactly. Don't use approximate numbers like 0.99005.

f[x_] = -(x/(10^20*(99005/100000 - Exp[x/10^12])))
Integrate[f[x], {x, 0, 10^9}]
(* Complicated exact expression involving Log and PolyLog *)

Evaluating this approximately indeed yields a small imaginary part.

%//N
(* 0.471182 - 2.86155*10^-12 I *)

However, this is an artifact of incomplete cancellation of the constant imaginary parts of the PolyLog component of the indefinite integral in step-by-step numerical evaluation. If, instead of asking for approximate evaluation, you ask a different question, you can show the result is real:

FullSimplify[Im[Integrate[f[x], {x, 0, 10^9}]]] == 0
(* True *)
$\endgroup$
  • $\begingroup$ For the general problem I use symbolic integration and then replace the variables with their value at the end but I still get this problem. Is it possible to make mathematica compute the integral properly? $\endgroup$ – DeanTheMachine May 26 '16 at 12:03
  • $\begingroup$ It computes the integral properly, and if you replace the variables with exact values you will get an exact (but complicated) result. If you replace the variables with inexact values, or use N[] to convert them, inexact arithmetic may fail to cancel out the imaginary part (and will be similarly inexact along the real axis). However, since you can show that the imaginary part is exactly zero (see above), you may simply use Re[] to get rid of the imaginary part if that matters. $\endgroup$ – John Doty May 26 '16 at 12:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.