# Nested NIntegrate with a nonseparable function [closed]

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}]
NIntegrate[i2[t1],{t1,0,∞}]


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.

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

No, you should use one NIntegrate command:

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

NIntegrate[
G[x, y, t1, t2], {t1, 0, ∞}, {t2, 0, t1}, {x, -∞, ∞}, {y, -∞, ∞}]

• 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? – dapias Feb 27 '17 at 3:39
• @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? – MarcoB Feb 27 '17 at 7:54
• @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". – user64494 Feb 27 '17 at 11:11
• @MarcoB you are right. Thank you! – dapias Feb 27 '17 at 16:17