Doubt computing multiple integrals by Monte Carlo method

31 Views Asked by At

The question is: Using Monte Carlo method, compute $\int_{0}^{1} \int_{-1}^{1} (x+y) dx dy.$

My resolution until now:

Let $g = x+y$.

$\Theta = E[g(U_{1}, ..., U_{n})]; U{1}, ..., U_{n}$ random variables uniform $(0, 1)$

Generate $k$ sets, each one with $n$ independent uniform $(0, 1)$ random variables.

Then, $g(U_1^{i}, ..., U_n^{i}); i = 1, ..., k$ are i.i.d with mean $\Theta$

So, $\Theta = \sum_{i=1}^{n} \frac{g(U_1^{i}, ..., U_n^{i})}{k}$

But I don't know how to keep it, as it is not supposed to do it computacionally.

1

There are 1 best solutions below

2
On

lets we want to estimate $I=\int_{x\in (0,1)} \int_{y\in (-1,1)} g (x,y) dx \ dy$.

Generate $(x_1,y_1),\cdots ,(x_n,y_n) $ form uniform $(0,1)\times (-1,1)$

  #R code
  n<-1000000
  x<-runif(n,0,1)
  y<-runif(n,-1,1)

Calculate $g(x_1,y_1), \cdots , g(x_n,y_n)$

  #R code
  gxy<-x+y

Calculate mean of $g(x_1,y_1), \cdots , g(x_n,y_n)$, that is , $\hat{I}=\frac{1}{n} \sum_{i=1}^{n} g(x_i,y_i)$

  #R code
  mean(gxy)
  #[1] 0.4998572