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));
}
}
Best Answer
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}$.