2

I am trying to use Monte Carlo Integration, which is nicely described in the answer here (Confusion about Monte Carlo integration).

I am using Monte Carlo Integration to evaluate $\int_0^1x^2\,dx$.

I set $w(x) = f(x)/g(x) = x^2/2x = x/2$

Then, I solved for $(1/n)\sum_i^nw(x_n) = (1/n)\sum_i^nx/2$

However, I do not know if this is a good solution. I would like to know of other ideas, and why they are better.

The reason I do not think this is a good solution is if I actually solve for:

$\int_0^1x^2\,dx$ = $x^3/3 = 1/3-0 = 1/3$

But when I look at my answer, the mean will be 1/4 (not 1/3). Had I used a different equation, such as $(1/n)\sum_i^nx/1.5$, then I will get a mean of 1/3, which is very close to what the true integration is. Thank you!

  • Shouldn't you be choosing your $x_n$ independently using a uniform distribution? In other words, you have $I = (1/n)\sum_i^n x_n^2$, where the $x_n$ are chosen using a uniform random number generator that generates values $x \in (0, 1)$. I ran the simulation and in $10000$ trials, I get $I = 0.3315$. – Amzoti Mar 20 '15 at 14:29
  • I am not an expert, so perhaps I am confused, but why do you set $w(x)=f(x)/g(x)$? It seems like the best approximation would simply be $\frac{1}{n}\sum\limits_{i=1}^nx_i^2$. – Peter Woolfitt Mar 20 '15 at 17:53
  • Perhaps see http://math.stackexchange.com/questions/1635250/ for more on Monte Carlo. – BruceET Feb 01 '16 at 17:40

2 Answers2

6

The algorithm for the Monte-Carlo approach is the following.

  • Generate $n$ uniform random points $x_n \in (0, 1)$
  • Set $\displaystyle I = \dfrac{1}{n} \sum_{i = 1}^n x_n^2$

We can then compare the error from the exact value versus the result from the Monte Carlo approach. Depending on how we coded up the Monte-Carlo Method, we can also estimate the error.

Example 1: Using the method above with $n = 1000$, we get the plot:

enter image description here

This produces $I = 0.3323369730904328$.

We can also use other improved Monte Carlo Methods.

Example 2: Using a Quasi-Monte-Carlo method with $n = 1000$, we get the plot:

enter image description here

This produces $I = 0.3332527188916689$.

Example 3: Using an Adaptive-Monte-Carlo method with $n = 1000$, we get the plot:

enter image description here

This produces $I = 0.333727841861132$.

Example 4: Using an Adaptive-Quasi-Monte-Carlo method with $n = 1000$, we get the plot:

enter image description here

This produces $I = 0.3333327629439999$.

In all cases we can compare that to the actual result of:

$$\displaystyle \int_0^1 x^2~ dx = \dfrac{1}{3}$$

amWhy
  • 209,954
Amzoti
  • 56,093
0

Just for completeness, you could also consider Crude-Monte Carlo and apply Median Latin Hypercube sampling as a variance reduction technique.

I have obtained the value $I = 0.33333231846082595$ with $n=1000$. For those interested in MLHS this post is a good summary: http://blog.lumina.com/2014/latin-hypercube-vs-monte-carlo-sampling/.

guille_NP
  • 106