# Double Integrals & Expected Value Monte Carlo Method

Tell me if I'm wrong

Let $\Omega = [a,b]\times[c,d]\subseteq\mathbb{R}^2$, then

$$\iint_\Omega \frac{1}{(x+y)^2}\mathop{}\!\mathrm{d}x\mathop{}\!\mathrm{d}y=\int_{c}^{d}\int_{a}^{b}\frac{1}{(x+y)^2}\mathop{}\!\mathrm{d}x\mathop{}\!\mathrm{d}y\tag{1}$$

is the double integral of $\frac{1}{(x+y)^2}$ over $\Omega$. I need to approximate the double integral above using the Expected Value Monte Carlo Method over $\Omega = [1,2]\times[3,4]$.

Let $\zeta:x\mapsto X = \zeta(x)$ a discrete pdf in $[a,b]\subseteq\mathbb{R}$, then

$$\mathbb{E}\left[\int_{a}^{b}\xi(x)\mathop{}\!\mathrm{d}x\right] = \frac{\mathrm{abs}(a-b)}{n}\sum_{i = 1}^{n}\xi\left[a+\mathrm{abs}(a-b)X_i\right]\tag{2}$$

give an aproximation of a mono-dimensional integral of a given function $\xi(x)$ over $[a,b]$. My question is—if what I said it's all correct, how can I modify the $(2)$ to handle a double integral?

Java Implementation

class doubleIntMonteCarlo
{
private static double sum = 0D;
private static double xSum = 0D;
private static double ySum = 0D;

private static double f(double x, double y)
{
return 1 / Math.pow( x + y , 2 );
}

public static double doubleIntMonteCarlo(double a, double b, double c, double d, int n)
{
for (int i = 0; i < n; i++)
{
xSum = a + c + (b - a) * Math.random();
ySum = (d - c) * Math.random();

sum += f(xSum, ySum);

//System.out.println(xSum + "  " + ySum + "  " + sum);
}
return sum / n;
}
}

public class MonteCarloIntegration
{
public static void main(String[] args)
{
System.out.println(doubleIntMonteCarlo.doubleIntMonteCarlo(1, 2, 3, 4, 10000000));
}
}

• Please modify $\Omega\subseteq\mathbb{R}^2 = [1,2]\times[3,4]$, which is certainly not what you want to say.
– Did
Commented Jun 17, 2014 at 16:41
• @Did I'm sorry, it's better now? Commented Jun 17, 2014 at 16:57
• Sure--except that I fail to understand why $[1,2]\times[3,4]$ disappeared.
– Did
Commented Jun 17, 2014 at 17:12
• @Did lol to be compatible and more clear with the snippet below! I'll fix this thank you. Commented Jun 17, 2014 at 17:14

Generate $(U_n)$ i.i.d. uniform in $[0,1]$ and consider $$I_n=\frac1n\sum_{k=1}^n\frac1{(4+U_{2k-1}+U_k)^2}.$$ Then $I_n$ converges almost surely to your integral and the error between $I_n$ and the integral is typically of order $1/\sqrt{n}$.

• This addresses the original version of the question, which was considering $[a,b]\times[c,d]=[1,2]\times[3,4]$. For a general product of intervals, consider the factor $(b-a)(d-c)$ and replace $4+U_{2k-1}+U_{2k}$ by $a+c+(b-a)U_{2k-1}+(d-c)U_{2k}$.
– Did
Commented Jun 17, 2014 at 17:11
• Please, can you clarify what you mean with $U_n$? I'm not saying that you are not clear, I mean to me. Should I generate $n$ random values in $[0,1]$? Commented Jun 17, 2014 at 17:42
• Yeah--actually $2n$ values but this is the idea.
– Did
Commented Jun 17, 2014 at 18:15
• Take a look at my Java implementation, I can't understand why it converges when the domain of integration is $\Omega = [1,2]\times[3,4]$ while it doesn't if I change it. Commented Jun 17, 2014 at 19:09
• For which Omega does it fail to converge?
– Did
Commented Jun 17, 2014 at 19:20