How to properly numerically integrate this double integral? I get always errors like NIntegrate failed to converge....


I tested different options, like Exclusions -> (3*t^2 + 1 == 0), Method -> "GlobalAdaptive", Method -> "LocalAdaptive", Method -> "Trapezoidal", WorkingPrecision -> 20, without success. If I approach the infinite integration boundaries by $\pm50$, or $\pm 100$, or $\pm200$ I always get the result $-6.28319$ close to $-2\pi$.

MMA 13

  • 7
    $\begingroup$ The correct answer is $-2\pi$, never mind what @user64494 says (s/he does not understand this kind of integral). The trick is to use $\int_{-\infty}^{\infty} e^{i t x}x dx = -2\pi i\delta'(t)$ where $\delta'$ is the first derivative of the Dirac $\delta$-function. $\endgroup$
    – Roman
    Commented Jan 18, 2022 at 17:37
  • $\begingroup$ Note that @MariuszIwaniuk switch the order of x and t. This is important, as the integral in the other order diverges. (Fubini's theorem does not apply.) -- oops, Mariusz deleted his comment.... $\endgroup$
    – Michael E2
    Commented Jan 18, 2022 at 17:59
  • 1
    $\begingroup$ @user64494 Once again, you need to read and understand Bracewell. $\endgroup$
    – John Doty
    Commented Jan 18, 2022 at 18:41
  • 6
    $\begingroup$ @user64494 I can only lead the horse to water but cannot make it drink. If you don't want to see why these integrals are the way they are, feel free to believe whatever you like. $\endgroup$
    – Roman
    Commented Jan 18, 2022 at 19:35
  • 4
    $\begingroup$ @user64494 Maybe you will believe your friends at MSE. math.stackexchange.com/questions/556567/dirac-delta-symmetry. Take the derivative of both sides of the well accepted equation mentioned there and you will get Roman's equation. $\endgroup$
    – Bill Watts
    Commented Jan 19, 2022 at 3:31

2 Answers 2


@Granular: Using Roman and Bill's hints:

$$ \delta(t)=\frac{1}{2 \pi}\int_{-\infty}^{\infty} e^{i t x}dx $$ then via Leibniz's rule we have: $$ \delta'(t)=\frac{i}{2\pi}\int_{-\infty}^{\infty} xe^{i t x} dx $$ so that we can write the double integral as:

$$ I=\int_{-\infty}^{\infty}\int_{-\infty}^{\infty}\left(\frac{1}{3 t^2+1} e^\frac{-t^2+i t}{3 t^2+1}\right)xe^{itx}{\rm d}x{\rm d}t $$ so that $$ I=-2\pi i\int_{-\infty}^{\infty}\frac{1}{3t^2+1}e^{\frac{-t^2+it}{3t^2+1}}\delta'(t){\rm d}t $$ and the last integral is easily evaluated analytically by Mathematica:

 1/(3 t^2 + 1)
   Exp[(-t^2 + I t)/(3 t^2 + 1)] D[DiracDelta[t], 
   t], {t, -\[Infinity], \[Infinity]}]
(* -i *)

or $I=-2\pi$

  • $\begingroup$ The double improper integral $$ I=\int_{-\infty}^{\infty}\int_{-\infty}^{\infty}\left(\frac{1}{3 t^2+1} e^\frac{-t^2+i t}{3 t^2+t}\right)xe^{itx}\,dx\,dt$$ does not exist in traditional math. If the one exists, then both iterated integrals should exist, but this is not true (see my comment to the question). All your formal transformations are built on the sand. $\endgroup$
    – user64494
    Commented Jan 19, 2022 at 17:27
  • 1
    $\begingroup$ Can you explain which steps in the analysis above you feel are wrong? Surely the first statement is correct. Is the application of Leibniz's rule ok? $\endgroup$
    – josh
    Commented Jan 19, 2022 at 17:47
  • 1
    $\begingroup$ @user64494. Traditional or Non-traditional math it is still math. $\endgroup$ Commented Jan 19, 2022 at 17:58
  • $\begingroup$ @MariuszIwaniuk: If you have arguments, please, state those instead of emotional ungrounded words. $\endgroup$
    – user64494
    Commented Jan 19, 2022 at 18:18
  • 2
    $\begingroup$ @user64494 What do you mean by "traditional math"? In the kind of math I use most frequently, we have been using delta functions for about 90 years, and the related Heaviside functions for about 130 years. The fact that you haven't studied it does not make it wrong or even non-traditional. The fact that you are reading this is testimony to its usefulness, since the data links that transmit these words to you depend on engineering that employs this math. $\endgroup$
    – John Doty
    Commented Jan 19, 2022 at 18:38

The integrals, where $f(x,t)$ is the OP's integrand, $$\int_{{\Bbb R}^2} f(x,y) \; dA \,, \qquad \int_{-\infty}^{\infty}\left(\int_{-\infty}^{\infty}f(x,t)\;dx\right)\,dt \,,$$ are, strictly speaking, divergent; however, the following seems to converge: $$ \int_{-\infty}^{\infty}\left(\int_{-\infty}^{\infty}f(x,t)\;dt\right)\,dx \,. \tag{1}$$ So if there is a way to assign a value to the integral, it should be the value in (1). How to assign values to divergent or improper integrals has been extensively discussed for a century but goes back further to rather famous work by Euler and Cauchy on sums and integrals. Those interested in the mathematics are encouraged to ask their questions on math.SE.

Here's the fastest way I found to compute (1), although due to how long things took, my explorations were limited. I was about to post it when @MariuszIwaniuk posted a comment that seemed similar, which was soon deleted. Nonetheless I waited, thinking an answer might be forthcoming, but soon another similar comment appeared.

integrand = Exp[(I t - t^2)/(3*t^2 + 1) + I*t*x]*x/(3*t^2 + 1);
liRe = NIntegrate`LevinIntegrandReduce[
   integrand /. {{x -> x}, {x -> -x}} // Mean // (* symmetrized *)
     Re // ComplexExpand // Simplify             (* real part only *)
   , t];
levinopts = 
  Normal@KeyDrop[liRe@"Rules", "Variables"] /. 
   HoldPattern["DifferentialMatrices" -> {dm_, ___}] :> 
    "DifferentialMatrix" -> dm;
lRe[x0_?NumericQ] := Block[{x = x0},
    ifunc[x, t] (* ignored when full Levin Rule options are given *),
    {t, -Infinity, Infinity},
    Method -> {"LevinRule", Sequence @@ levinopts},
    PrecisionGoal -> 6, MaxRecursion -> 20]

The value (of the real part) of (1) agrees with $2\pi$ to seven digits in this approximation:

PrintTemporary@Dynamic@{Clock[Infinity]}; (* running timer *)
2 NIntegrate[
 {x, 0, Infinity}, PrecisionGoal -> 4] // AbsoluteTiming
Last[%] + 2 Pi
(*  {77.6966, -6.28319}  *)
(*  3.29801*10^-8        *)
  • $\begingroup$ Is this a numerical integration without warning messages or were the warning messages suppressed? Would be nice to give a reference about improper integrals of this type. $\endgroup$ Commented Jan 18, 2022 at 21:19
  • $\begingroup$ @granularbastard I got no messages (V13.0). $\endgroup$
    – Michael E2
    Commented Jan 18, 2022 at 21:20
  • $\begingroup$ The code fails if we double the values for both PrecisionGoal. Why is it so instable? $\endgroup$ Commented Jan 18, 2022 at 21:35
  • 1
    $\begingroup$ @granularbastard The integral is oscillatory, which invites numerical instability. The Levin rule tries to handle that in the $t$ integral. However, the maximum magnitude of the integrand (over $t$) is roughly proportional to $x$ as $x \rightarrow \infty$. As $x$ grows, numerical instability seems to return (that's my guess). Theoretically, it should be handled by increasing WorkingPrecision, but the computations take too long for me to verify it. $\endgroup$
    – Michael E2
    Commented Jan 18, 2022 at 21:48
  • 5
    $\begingroup$ @user64494 (1) For a given $x$, the $dt$ integral converges, so strictly speaking the approximates the value, not the principal value. Do not let the numerical tricks fool you. They are done for speed and accuracy. (2) I already said the double integral diverges, and I don't understand why it needs repeating. (3) Your last action shows what a jerk you can be. $\endgroup$
    – Michael E2
    Commented Jan 18, 2022 at 22:04

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.