4
$\begingroup$

Code for reproducing is below:

Integrand[x_] := ((x + 1) Abs[x] Log[(x + 1)^2/Abs[x]^3])/((x + 1)^2 - Abs[x]^3);
    
NIntegrate[Integrand[x], {x, -10000000, 10000000}]
NIntegrate[Integrand[x], {x, -Infinity, Infinity}]

The first instance of NIntegrate gives $2.48398$, and one can check by plotting the result of NIntegrate as a function of the integration limits that the integral appears to converge to this answer for very large integration limits. However, the second instance of NIntegrate gives a completely different answer of $1.75434 \times 10^{8}$. What's going on here, and how can I make the two integrals agree? I think something that NIntegrate might be having trouble with is that the convergence of the integral requires the fact that the integrand is essentially odd for very large $|x|$ and these contributions tend to cancel out. Ideally I'd like to find some way to get Mathematica to deal with this properly with the infinite integration range, so that I don't have to keep remembering to exchange the infinite integration limits with large finite values every time I need to do an integral like this.

$\endgroup$
9
  • 1
    $\begingroup$ I get convergence error when I run both. That suggests to me that neither is right. What happens if you adjust the computations to converge? $\endgroup$
    – Michael E2
    Feb 11, 2021 at 19:31
  • $\begingroup$ That's strange, are you sure you copied them correctly? I just opened up a new file, copied and pasted the code, and ran it on Mathematica 12.1.1.0 and I get the answers I've written in both cases. $\endgroup$ Feb 11, 2021 at 19:35
  • $\begingroup$ How do I see these convergence errors? I'm not seeing anything like that on my side. I'm plotting the integrand and it doesn't look like there should be any convergence errors, so I'm not really sure what I should be changing. $\endgroup$ Feb 11, 2021 at 19:39
  • $\begingroup$ No, I've opened up the "Messages" window and nothing is coming up when I evaluate these integrals. $\endgroup$ Feb 11, 2021 at 19:42
  • 1
    $\begingroup$ Series[((x + 1) RealAbs[x] *Log[(x + 1)^2/RealAbs[x]^3])/((x + 1)^2 - RealAbs[x]^3), {x, Infinity, 1}] results in $O\left(\left(\frac{1}{x}\right)^2\right)+\frac{\log (x)}{x}$ and Series[((x + 1) RealAbs[x] *Log[(x + 1)^2/RealAbs[x]^3])/((x + 1)^2 - RealAbs[x]^3), {x, -Infinity, 1}] performs $\frac{\log (-x)}{x}+O\left(\left(\frac{1}{x}\right)^2\right)$. This implies the improper integral under consideration diverges. Maybe, the one exists as its principal value. In any case, NIntegrate badly handles improper integrals over the reals. $\endgroup$
    – user64494
    Feb 11, 2021 at 19:59

2 Answers 2

5
$\begingroup$

Update

Assuming that the principal value is wanted, the method below is probably the best way, which computes the PV at infinity by reflecting the integration over the negative axis onto the positive axis.

NIntegrate[Integrand[x] + Integrand[-x], {x, 0, Infinity}]

(*  2.8130684254425558`  *)

@user64494 pointed out that it's a divergent integral (at infinity) and that Method -> "PrincipalValue" computes the principal value only at finite points and not at infinity. Add the singularity at 1 to the interval to get higher precision:

    NIntegrate[Integrand[x] + Integrand[-x], {x, 0, 1, Infinity},...]

(See older part below for discussion of the singularities.)

The OP's NIntegrate[Integrand[x], {x, -10000000, 10000000}] in essence approximates the PV.


I can get them to agree in this way:

sing = SortBy[
   x /. Solve[FunctionSingularities[Integrand[x], x], x, Reals], N];
N@sing

(*  {-1., -0.56984, 0., 2.1479}  *)

NIntegrate[integrand[x], 
 Evaluate@{x, -10000000, Sequence @@ sing, 10000000}]
NIntegrate[integrand[x],
 Evaluate@{x, -Infinity, Sequence @@ sing, Infinity}, 
 WorkingPrecision -> 32, PrecisionGoal -> 6, AccuracyGoal -> 20, 
 Method -> "PrincipalValue"]

(*
  2.813065409383123       (no warnings)
  2.81306842613267712727  (warnings omitted)
*)

At -1 and 0, there seem to be infinite derivatives, so-called "weak" singularities. At the other two "singularities" there might be numerical difficulties from subtractive cancellation (e.g. they're where the denominator (1 + x)^2 - Abs[x]^3 is zero). Weak singularities tend to make convergence harder.

$\endgroup$
5
  • $\begingroup$ Thanks for clarifying, I appreciate it. Looks like the integrand was more subtle than just plotting it would suggest. $\endgroup$ Feb 11, 2021 at 20:11
  • 1
    $\begingroup$ @HenryShackleton You're welcome. Somehow I feel that NIntegrate is accidentally computing the principal value $\lim_{A\rightarrow\infty} \int_{-A}^A f(x) \, dx$ in this case. I'm not sure it does the principal value at infinity. That's why I'm getting warnings... $\endgroup$
    – Michael E2
    Feb 11, 2021 at 20:15
  • 1
    $\begingroup$ @MichaelE2: As I was informed by WRTS, NIntegrate[integrand[x], {x, -Infinity, 0, Infinity}, Method -> "PrincipalValue"] does not calculate $\lim_{A\rightarrow\infty} \int_{-A}^A \,Intagrand(x) dx$. The command takes $0$ as the singularity for principal value. yarcik demonstrates the way to handle that principal value. In fact, a true answer is is done by him. $\endgroup$
    – user64494
    Feb 11, 2021 at 20:30
  • $\begingroup$ @user64494 I don't know what WRTS is, but that is what I deduced from my experiments. Thanks for the confirmation. $\endgroup$
    – Michael E2
    Feb 11, 2021 at 20:34
  • $\begingroup$ @MichaelE2: Wolfram Research Technical Support. $\endgroup$
    – user64494
    Feb 11, 2021 at 20:35
6
$\begingroup$

Numerical integration can be without any problems by splitting the integration into two parts:

f1 = FullSimplify[Integrand[x], Assumptions -> x > 0];
f2 = FullSimplify[Integrand[-x], Assumptions -> x > 0];
NIntegrate[f1 + f2, {x, 0, ∞}]
(*2.81307*)

Higher accuracy can be reached (again without any warnings as follows)

NIntegrate[f1 + f2, {x, 0, 1, ∞}, WorkingPrecision -> 100]
 (*2.81306842544297991357319331946335010348754523474644575568568457957304\
   5154609418329813658075049081527*)
$\endgroup$
3
  • $\begingroup$ I get no warnings, too, with my last update. We pretty much have the same method there. $\endgroup$
    – Michael E2
    Feb 11, 2021 at 20:20
  • $\begingroup$ There is not any principal value in this case. $\endgroup$
    – user64494
    Feb 11, 2021 at 20:25
  • $\begingroup$ Just add the singularity in that case. But there's no need at machine precision. $\endgroup$
    – Michael E2
    Feb 11, 2021 at 20:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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