I am faced to integrate numerically a multivariable non-separable function $G(x,y,t_1,t_2)$. This is the integral in question

$$ \int_{0}^\infty dt_1 \int_{0}^{t_1} dt_2 \int_{-\infty}^\infty dx \int_{-\infty}^\infty dy \, G(x,y,t_1,t_2) \, . $$

For concreteness, consider that $G$ is given by $$ G(x,y,t_1,t_2) = \frac{e^{-(x-y)^2/(t_1-t_2)}}{x+y+t_1+t_2} \, ,$$ but in general is a nonseparable function.

I wrote the following code (inspired by this post)

G = Exp[-(x-y)^2/(t1-t2)]/(x+y+t1+t2)
i1[t1_?NumericQ, t2_ ?NumericQ] :=  i1[t1, t2] = NIntegrate[G, {x,-∞, ∞}, {y, -∞,∞}]
i2[t1_ ?NumericQ]:= i2[t1] = NIntegrate[i1[t1,t2],{t2,0,t1}]

And I was wondering if my approach is correct. I am not interested in the result of this particular function $G$, what is important for me is the approach.

  • $\begingroup$ Does the integral under consideration converge at all? $\endgroup$ – user64494 Feb 27 '17 at 11:16

No, you should use one NIntegrate command:

G[x_?NumericQ, y_, t1_, t2_] := 
  Exp[-(x - y)^2/(t1 - t2)]/(x + y + t1 + t2);

 G[x, y, t1, t2], {t1, 0, ∞}, {t2, 0, t1}, {x, -∞, ∞}, {y, -∞, ∞}]
|improve this answer|||||
  • $\begingroup$ I guess that the iterated integral makes inconvenient to evaluate the integral as you suggest. I mean, if the limits of $t_2$ were independent of any variable you would right, but this is not the case. What do you think? $\endgroup$ – dapias Feb 27 '17 at 3:39
  • 4
    $\begingroup$ @dapias There is nothing wrong with having limits depending on the values of other variables, as long as those limits are specified after the variable on which they depend. I think a complication in your case is the function you proposed as an example, but you can see e.g. that NIntegrate[x^2 - 10 Sin[x y/10], {x, 0, Pi}, {y, -x, 2 x}] returns a value with no problem, even though the limits of integration of $y$ explicitly depend on $x$. Or am I misunderstanding your question? $\endgroup$ – MarcoB Feb 27 '17 at 7:54
  • $\begingroup$ @Anton Antonov: Does the integral under consideration converge at all? Look at the denominator in G. Mma says "NIntegrate::errprec: Catastrophic loss of precision in the global error estimate due to insufficient WorkingPrecision or divergent integral". $\endgroup$ – user64494 Feb 27 '17 at 11:11
  • $\begingroup$ @MarcoB you are right. Thank you! $\endgroup$ – dapias Feb 27 '17 at 16:17

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