0
$\begingroup$

For a time I am trying to solve this task:

Using Monte Carlo method, approximate the integral $\int_{-1}^{1}\int_{-1}^{1}x^{2}cos(y)dxdy$ using the given realizations of a random vector which has independent components uniformally distributed within the interval $[0;1]$: $$u_{1}=[0.90;0.36] \\ u_{2}=[0.66;0.08] \\u_{3}=[0.77;0.93] $$

I'm trying to solve this in the following way, knowing that the function in question is symmetric with respect to axes $x$ and $y$:

  1. I calculate the values of the function in points $u_{1}, u_{2}, u_{3}$: $$f(u_{1})=f(0.90,0.36)=0.758 \\ f(u_{2})=f(0.66,0.08)=0.434 \\ f(u_{3})=f(0.77,0.93)=0.354 $$
  2. I calculate the average value of the function $$f_{\phi}=0.515$$
  3. To get the value of the integral I multiply the average value with the area of the integration range $$\int_{-1}^{1}\int_{-1}^{1}f(x,y)dxdy=f_{\phi}*A=0.515*4=2.061$$

The result I get is wrong - it sgould be something around $1.12$. What am I doing wrong?

EDIT: I stumbled upon this kind of solution but have no idea where does it result from. We somehow change the variables of the integrated function with respect to the integration range. $$ u=\frac{x-a}{b-a}=\frac{x-(-1)}{1-(-1)} \to x=2u-1 \to \frac{du}{dx}=\frac{1}{2} \to dx=2du$$ $$ v=\frac{y-a}{b-a}=\frac{x-(-1)}{1-(-1)} \to y=2v-1 \to \frac{dv}{dy}=\frac{1}{2} \to dy=2dv$$

This leads to $$\int_{-1}^{1}\int_{-1}^{1}(2u-1)^{2}cos(2v-1)2du2dy$$ Following the same algorithmm as before, calculating values of the function $f(u,v)=(2u-1)^{2}cos(2v-1)$ in the points $u_{1}, u_{2}, u_{3}$, the avreage value multiplied by the area gives me the result of $1,164$ which is a good approximation of the integral.

  • 1
    I have no idea what you are trying to do. What is $f$? 'Integral of the function'? Why not 'Integral'? Where does $u_{i}$ enter the integral?2017-02-16
  • 0
    @Jan - you're right, a word mistake. $f$ is of course a function $f(x,y)=x^{2}cos(y)$2017-02-16
  • 0
    @MrLoon: I added an edit...2017-02-16

2 Answers 2

0

The integral you have to evaluate is supposed to give the volume of a solid above $[-1,1]\times[-1,1]$ and below the surface determined by your function whose graph is given below:

enter image description here

It is obvious that over $[-1,1]\times[-1,1]$ surface is below $z=1$ and above $0$.

Let's see what if we generate pairs of random variables $\{(X_i,Y_i)\}$ uniformly distributed over $[0,1]\times[0,1]$. Then the average

$$\lim_{N\to \infty}\frac1N\sum_1^N X_i^{2}\cos(Y_i)=$$ $$E[X_i^{2}\cos(Y_i)\mid (X_1,Y_1)\in[0,1]\times[0,1]]=\int_{0}^{1}\int_{0}^{1}x^{2}\cos(y)dxdy$$

with probability one (law of large numbers). So the original integral equals the average times $4$.

Your calculation is OK. The difference from the true value of the integral is a result of the little number of data. I did an experiment with $1000$ data and the result was $1.12796$. Working with data sets of three numbers I even got $0.17$ as an approximation of the integral.

I guess that the moral of the original example partly is that small datasets may give very bad bad approximations.

  • 0
    tanks for the feedback, but I am afraid that as it's an example of the exam task and must be done by hand. Please see my edited post for an example solution.2017-02-16
  • 0
    @MrLoon: Having read your edit, I realize that I have no idea about the MCM you use. But, I still believe that it makes no sense to say that the approximation is good or not if we use three samples. What is I change your pair and ask you to redo your calculations...2017-02-16
  • 0
    I choose this equation: $$I \approx V \frac{1}{N}\sum_{i=1}^n f(x_{i})$$2017-02-16
  • 0
    Oh, I understand. I1ll edit my answer then.2017-02-16
  • 0
    I've edited my answer.2017-02-16
  • 0
    I've edited again. Please take a look.2017-02-16
0

Observe that your three sample points are taken from the region $[0,1]\times[0,1]$, but the integral is over $[-1,1]\times[-1,1]$. So, your estimate is for the integral $\int_0^1\int_0^1f(x,y)\,dx\,dy$ instead of $\int_{-1}^1\int_{-1}^1f(x,y)\,dx\,dy$. You need to scale the sample points so that they’re uniformly distributed over the correct region, which is what the change of variables in your edit accomplishes.