4
$\begingroup$

I'm running Mathematica 11.3.0.0. The inverse Laplace transform of $1/(s^2-1)$, evaluated at $t=1$ gives

 InverseLaplaceTransform[1/(s^2 - 1), s, t] /. t -> 1    
 (* (-1 + E^2)/(2 E) *)

which is correct. Explicit evaluation as a symbolic integral

 (2*Pi*I)^(-1)*Integrate[Exp[s]/(s^2 - 1), {s, 2 - I*Infinity, 2 + I*Infinity}]

gives the same correct result $(e^2-1)/(2e)=1.1752$. However, numerical evaluation of the integral is way off,

 (2*Pi*I)^(-1)*NIntegrate[Exp[s]/(s^2 - 1), {s, 2 - I*Infinity, 2 + I*Infinity}]
 (* -0.18394 - 2.70877*10^-14 I *)

The imaginary part is negligibly small, as it should be, but the real part differs by almost a factor of ten from the correct value (without any error messages). Any idea what is going on?


As noted by AccidentalFourierTransform, the correct result is returned by

 (2*Pi*I)^(-1)*NIntegrate[Exp[s]/(s^2 - 1), {s, 2 - I*Infinity, 2,2 + I*Infinity}]
 (* 1.1752 + 0. I *)

Perhaps this is documented somewhere, that the integration path should be explicitly specified?

$\endgroup$
1
  • 4
    $\begingroup$ Interesting. It seems that for some reason you have to force the integration contour to go around the singularities on the right. The code (2*Pi*I)^(-1)* NIntegrate[Exp[s]/(s^2 - 1), {s, 2 - I*Infinity, 2, 2 + I*Infinity}] returns the correct result (notice the path, {s, 2 - I*Infinity, 2, 2 + I*Infinity}). Hmmm. $\endgroup$ Commented Jun 13, 2018 at 0:00

3 Answers 3

4
$\begingroup$

Amplifying @John's answer, first note:

2 - I Infinity //InputForm

DirectedInfinity[-I]

The real part has been discarded. So both the Integrate and NIntegrate versions are using the limits:

{s, -I Infinity, I Infinity}

instead, with the real part suppressed. Now, the two outputs are different, so which is correct? Typically, when there is a discrepancy between Integrate and NIntegrate (where NIntegrate produces a results without error messages), then it is more likely that NIntegrate is correct, since NIntegrate doesn't need to check branch cut/pole issues associated with the antiderivative that is computed by Integrate. That is the case here. Compare:

Integrate[Exp[s]/(s^2-1),{s, -I*Infinity, I*Infinity}]/(2 Pi I) //N

NIntegrate[Exp[s]/(s^2-1),{s, -I*Infinity, I*Infinity}]/(2 Pi I)

1.1752

-0.18394 - 2.70877*10^-14 I

The Integrate result takes the difference of the antiderivative at the two limits of integration, but it may not be clear which path this result corresponds to. On the other hand, the NIntegrate result always uses the linear path between the limits, i.e., the path that goes through the origin. Redoing the integrals by specifying that the path goes through the origin:

Integrate[Exp[s]/(s^2-1),{s, -I*Infinity, 0, I*Infinity}]/(2 Pi I) //N

NIntegrate[Exp[s]/(s^2-1),{s, -I*Infinity, 0, I*Infinity}]/(2 Pi I)

-0.18394 + 0. I

-0.18394 - 2.70877*10^-14 I

Now, the two results agree. If we use a path that goes through the point 2:

Integrate[Exp[s]/(s^2-1),{s, -I*Infinity, 2, I*Infinity}]/(2 Pi I) //N

NIntegrate[Exp[s]/(s^2-1),{s, -I*Infinity, 2, I*Infinity}]/(2 Pi I)

1.1752 + 0. I

1.1752 + 0. I

These results agree with the original Integrate result, so we see that just subtracting the antiderivative at the limits of integration corresponds to the path that goes around the singularities at $\pm 1$ on the right.

Addendum

@xzczd asked whether it is possible to confirm that NIntegrate does drop the real part. One piece of evidence:

Short[
    Last @ Reap @ NIntegrate[
        Exp[s]/(s^2-1),
        {s, 2-I Infinity, 2+I Infinity},
        EvaluationMonitor:>Sow[s]
    ],
    10
]

{{0. -61.8145 I,0. -11.1974 I,0. -4.17292 I,0. -1.95969 I,0. -1. I,0. -0.510285 I,0. -0.23964 I,0. -0.0893062 I,0. -0.0161774 I,0. -374.81 I,0. -22.5193 I,0. -6.53258 I,0. -2.81288 I,0. -1.39298 I,0. -0.717883 I,<<236>>,0. -0.444442 I,0. -0.390297 I,0. -0.354513 I,0. -0.336879 I,0. -0.329806 I,0. -0.312805 I,0. -0.280854 I,0. -0.238097 I,0. -0.190411 I,0. -0.142857 I,0. -0.0989569 I,0. -0.0612234 I,0. -0.0317034 I,0. -0.0118667 I,0. -0.0019933 I}}

All of the evaluation points have a real part of 0.

$\endgroup$
2
  • $\begingroup$ Hmm… NIntegrate has the attribute HoldAll, doesn't it? Well, I know that HoldAll doesn't mean the argument will never be evaluated and NIntegrate does evaluate its first argument after "hold" it, but, is there a way to verify that 2 - I Infinity is indeed evaluated internally? $\endgroup$
    – xzczd
    Commented Jun 13, 2018 at 15:30
  • $\begingroup$ @xzczd See addendum. $\endgroup$
    – Carl Woll
    Commented Jun 13, 2018 at 15:44
2
$\begingroup$

Following up on @AccidentalFourierTransform's comment, I suspect that NIntegrate, being a numerical method, evaluates the limits of integration numerically. 2 + I*Infinity becomes I*Infinity, and the real displacement of the contour is lost. Integrate, which can deal in symbolic limits, seems to peek at the limits before evaluating, and figures out what you mean even though expressions like 2 + I*Infinity are dubious.

$\endgroup$
1
  • $\begingroup$ Plausible. A possible evidence: Clear[a]; NIntegrate[Exp[s]/(s^2 - 1), {s, a - I \[Infinity], a + I \[Infinity]}]/(2 \[Pi] I) $\endgroup$
    – xzczd
    Commented Jun 13, 2018 at 13:53
1
$\begingroup$

The problem is already explained thoroughly by Carl, I just want to mention that in v13.3 ContourIntegrate is introduced, which can avoid the issue caused by I ∞ in a more natural way:

1/(2 π I) ContourIntegrate[Exp[s]/(s^2 - 1.), s ∈ InfiniteLine[{2, 0}, {0, 1}]]

enter image description here

ContourIntegrate can also be used to calculate the integral symbolically, of course:

1/(2 π I) ContourIntegrate[E^s/(s^2 - 1), s ∈ InfiniteLine[{2, 0}, {0, 1}]]

enter image description here

$\endgroup$

Your Answer

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

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