Monte Carlo Integration

In summary: This gives you the correct result of 2. In summary, to use Monte Carlo Integration, you need to generate a large number of random numbers in the integration interval, evaluate the function for each number, and then take the average of those values. To get the correct result for the integral, you also need to multiply this average by the length of the integration interval.
  • #1
econmajor
5
1

Homework Statement


$$f(x)=NormalPDF(x,2,1)+NormalPDF(x,2,(1/2)^2)$$.

where NormalPDF(a,b) is the PDF for a normal distribution with mean a and variance b.

Use Monte Carlo Integratoion to find: $$\int_{-10}^{10}f(x)dx$$

Homework Equations


The solution to this integration is 2.
I use the method described in this video:


The Attempt at a Solution


What I have done is as follows:
- draw n (=5000) random numbers uniformly distributed from -10 to 10. in R: runif(n,-10,10)
- evaluate the function f for each of the n randomly distributed numbers so I end up with n different values of f
- find the mean of those values and that is my integral.

I end up with 0.1 instead of 2. What do I do wrong? When I experiment with $$\int_{0}^{1}\exp(-x^2/2)$$ and use the same method I get the correct result

When I multiply by 20 then I get the correct answer. I assume it has something to do with my integration Interval. But I can't see why it gets me the correct answer when mulitiplying by 20
 
Last edited:
Physics news on Phys.org
  • #2
By generating a large number of random numbers ##x## in the integration interval [-10,10] and taking the average of ##f(x)## you have estimated the mean of ##f(x)## in the interval. The mean of a function ##f## over an interval ##[a,b]## is defined as
$$\frac{\int_a^b f(x)dx}{b-a}$$
So, to estimate the integral, you need to multiply your estimate of the mean (0.1) by ##(b-a)## which in this case is ## (10--10)=20##.
 
  • Like
Likes Orodruin

1. What is Monte Carlo Integration?

Monte Carlo Integration is a numerical method used to approximate the value of an integral by using random sampling. It is based on the idea that the average value of a function over a given interval can be estimated by taking the average of the function evaluated at random points within the interval.

2. How does Monte Carlo Integration work?

To perform Monte Carlo Integration, a large number of random points are generated within the interval of the integral. These points are then used to compute the average value of the function over the interval. The result can be interpreted as an estimate of the integral value.

3. What are the advantages of using Monte Carlo Integration?

One advantage of Monte Carlo Integration is that it can be used to approximate integrals of complex functions that do not have analytic solutions. It also has a high degree of accuracy and can handle high-dimensional integrals that may be difficult to evaluate using other numerical methods.

4. How do you determine the number of samples needed for Monte Carlo Integration?

The number of samples needed for Monte Carlo Integration depends on the desired level of accuracy. Generally, the more samples that are used, the more accurate the approximation will be. The number of samples can also be adjusted based on the complexity of the function being integrated.

5. What are some potential limitations of Monte Carlo Integration?

One limitation of Monte Carlo Integration is that it can be computationally expensive, especially for high-dimensional integrals. It also relies on randomness and may not always produce accurate results. Additionally, it may not be suitable for all types of integrals, such as those with discontinuities or singularities.

Similar threads

  • Calculus and Beyond Homework Help
Replies
2
Views
416
  • Programming and Computer Science
Replies
1
Views
946
  • Calculus and Beyond Homework Help
Replies
9
Views
749
  • Programming and Computer Science
Replies
1
Views
735
  • Calculus and Beyond Homework Help
Replies
23
Views
930
  • Calculus and Beyond Homework Help
Replies
9
Views
535
  • Set Theory, Logic, Probability, Statistics
Replies
7
Views
1K
  • Calculus and Beyond Homework Help
Replies
3
Views
246
  • Calculus and Beyond Homework Help
Replies
10
Views
418
  • Calculus and Beyond Homework Help
Replies
4
Views
1K
Back
Top