• Support PF! Buy your school textbooks, materials and every day products via PF Here!

Monte Carlo Integration

1. The problem statement, all variables and given/known data

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$$
2. Relevant equations
The solution to this integration is 2.
I use the method described in this video:

3. 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:


Science Advisor
Homework Helper
Insights Author
Gold Member
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##.

Want to reply to this thread?

"Monte Carlo Integration" You must log in or register to reply here.

Physics Forums Values

We Value Quality
• Topics based on mainstream science
• Proper English grammar and spelling
We Value Civility
• Positive and compassionate attitudes
• Patience while debating
We Value Productivity
• Disciplined to remain on-topic
• Recognition of own weaknesses
• Solo and co-op problem solving