This question already has an answer here:

I'm trying to calculate the following indefinite integral:

$$ \int \log \left(\left(\frac{\lambda ^2}{a \lambda ^2+b}+\text{$\Delta $0}\right)^2\right) \, d\lambda $$

which is producing the following result:

$$ \lambda \log \left(\left(\frac{\lambda ^2}{a \lambda ^2+b}+\text{$\Delta $0}\right)^2\right)+\frac{4 \sqrt{b} \sqrt{\text{$\Delta $0}} \tan ^{-1}\left(\frac{\lambda \sqrt{a \text{$\Delta $0}+1}}{\sqrt{b} \sqrt{\text{$\Delta $0}}}\right)}{\sqrt{a \text{$\Delta $0}+1}}-\frac{4 \sqrt{b} \tan ^{-1}\left(\frac{\sqrt{a} \lambda }{\sqrt{b}}\right)}{\sqrt{a}} $$

This results seems correct except that for some values of a, b, and $\Delta_0$, it is returning a complex number. For example:

Integrate[Log[(Δ0 + λ^2/(a λ^2 + b))^2], λ] 
  /. a -> 0.87 /. b -> 2000 /. Δ0 -> -1.1 /. λ -> 300

gives the result

-1706.06 - 1421.21 I

Numerically integrating the function it seems as if the real part of the expression is correct. For example:

  Log[(Δ0 + λ^2/(a λ^2 + b))^2] /. a -> 0.87 /. b -> 2000 /. Δ0 -> -1.1, 
  {λ, 0, 300}]



My question is twofold:

  1. Why is Mathematica returning an expression for this integral which can evaluate to a complex number?

  2. Is it possible to obtain an expression which always evaluates to a real number, ideally one which contains no complex numbers as intermediate results in the expression?


marked as duplicate by MarcoB, m_goldberg, José Antonio Díaz Navas, Henrik Schumacher, rhermans Jul 11 '18 at 17:36

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 1
    $\begingroup$ A numerical value for an integral only really makes sense if you specify limits. I suggest you determine suitable limits, and you may then find that you get a purely real answer. $\endgroup$ – mikado Jul 10 '18 at 20:41
  • $\begingroup$ @mikado I'm evaluating the expression from $\lambda$ = 0 to $\lambda$ = 300. $\endgroup$ – user545424 Jul 10 '18 at 20:43
  • 2
    $\begingroup$ @user545424 Then use Integrate[..., {λ, 0, 300}] instead of Integrate[..., λ]. $\endgroup$ – AccidentalFourierTransform Jul 10 '18 at 20:45
  • 5
    $\begingroup$ In evaluating an indefinite integral, Mathematica makes certain assumptions about the symbolic parameters. If you then substitute values that don't satisfy these assumptions, it can give you the wrong answer. $\endgroup$ – mikado Jul 10 '18 at 21:08
  • 1
    $\begingroup$ Just found this post blog.wolfram.com/2008/01/19/… which seems to explain things pretty well. Thanks! $\endgroup$ – user545424 Jul 10 '18 at 21:24