Why Does Multiplying by 20 Correct My Monte Carlo Integration Result?

econmajor
Messages
5
Reaction score
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
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   Reactions: Orodruin

Similar threads

Replies
4
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 19 ·
Replies
19
Views
4K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 6 ·
Replies
6
Views
3K
  • · Replies 7 ·
Replies
7
Views
2K
Replies
7
Views
4K
  • · Replies 9 ·
Replies
9
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 12 ·
Replies
12
Views
4K