Monte Carlo double integral over surface of $|x|+|y| \leq 1$

368 Views Asked by At

$\iint_{|x|+|y|\le1}\!x^2\,dxdy$

I am supposed to calculate this by using Monte Carlo integration. Can anyone give basic hints or directions? I know the idea behind the Monte Carlo integration method but my brain can't seem to be able to grasp any straw at how to solve this.

1

There are 1 best solutions below

0
On BEST ANSWER

Enclose your integration in $\displaystyle{\left[-1,1\right)^{\,2}}$. The Monte-Carlo integration becomes $\left(~overline\ \overline{\phantom{AAA}}\mbox{means average with an uniform distibution over}\ \left[-1,1\right)^{\,2}~\right)$ \begin{align} S_{N} & = \sum_{i = 1}^{N}x_{i}^{2} \left[\vphantom{\Large A}\left\vert x_{i}\right\vert + \left\vert y_{i}\right\vert \leq 1\right] \\[2mm] \overline{S_{N}} & = N\ \overline{x^{2} \left[\vphantom{\Large A}\left\vert x\right\vert + \left\vert y\right\vert \leq 1\right]} = N\int_{-1}^{1}\int_{-1}^{1}{1 \over 4} \left[\vphantom{\Large A}\left\vert x\right\vert + \left\vert y\right\vert \leq 1\right]x^{2} \,\mathrm{d}x\,\mathrm{d}y \\[5mm] & \implies \int_{-1}^{1}\int_{-1}^{1} \left[\vphantom{\Large A}\left\vert x\right\vert + \left\vert y\right\vert \leq 1\right]x^{2} \,\mathrm{d}x\,\mathrm{d}y = 4\,{\overline{S_{N}} \over N} \approx \bbox[10px,#ffd,border:1px groove navy] {4\,{S_{N} \over N}} \end{align}

The following code is a $\texttt{javascript}$ script which can be run in a terminal with $\texttt{node.js}$:

"use strict";
const ITERATIONS = 10000;
let i = 0, theSum = 0, x = null, y = null;

while (i < ITERATIONS) {
      x = 2.0*Math.random() - 1.0;
      y = 2.0*Math.random() - 1.0;
      if (Math.abs(x) + Math.abs(y) <= 1.0) theSum += x*x;
      ++i;
}

console.log(4.0*(theSum/ITERATIONS));

A typical "run" yields $\bbox[10px,#ffd,border:1px groove navy]{\displaystyle 0.3302123390009306}$. The exact result is $\bbox[10px,#ffd,border:1px groove navy] {\displaystyle{1 \over 3}}$.