Aproximate Double Integral Result Using The Monte Carlo Method Getting 2 different results

73 Views Asked by At

My task is to approximate a result using the Monte Carlo method programatically. The integral in question is the following: $\iint (2x+y) dxdy$

The integral is delimited by the graph axes (xOy) and by the segment x+y=3. From the last line I've deduced that the interval for x is [0,3] and for y is [0,3] obtaining some kind of triangle that has the vertices on (0,0), (0,3) and (3,0).

What I've tried so far yielded the following results:

$\int^3_0\int^3_0 (2x+y) dxdy = \int^3_0 (x^2+xy)dy$

Then I've replaced x with the limit ends for it (3,0):

$\int^3_0 (x^2+xy)dy = \int^3_0 (9+3y) - 0dy$

Then I proceeded to calculate the integral by y.

$\int^3_0 (9+3y)dy = 9y+(3y^2)/2$

Then I've replaced the y with the limit terms (3,0):

$9*3+(3*9)/2 - 0 = 27 + 27/2 = 27 + 13,5 = 40,5$

So the final result that I got by manually integrating was 40,5.

Then I tried to aproximate this result using C#, but I'll write in pseudocode:

sum=0
for i->number_of_iterations
    x = random between 0 and 3
    y = random between 0 and 3 - x
    sum = sum + 2 * x + y
end for
sum = sum * (xUpperLimit-xLowerLimit) * (yUpperLimit - yLowerLimit) / number_of_iterations

However, the result that it tends to converge to is 33,75. What am I doing wrong? And, is the interval that I've deduced for x and y even the right one?

1

There are 1 best solutions below

0
On BEST ANSWER

You are choosing $x$ from a uniform distribution on $[0,3]$, but this is wrong: over the triangle of integration, $x$ is more likely to be small than large. This is the source of your error.

You have to choose a point $(x,y)$ from a uniform distribution over the triangle of integration. The simplest way is to choose $x$ and $y$ separately from uniform distibutions over $[0,3]$, and reject those $(x,y)$ pairs with $x+y>3$. Or to avoid waste, instead of rejecting such pairs you can use $(3-x,3-y)$ instead.