Monte Carlo Integration with a simple example

In this article, I will explain Monte Carlo Integration.

How can we do the “Integration”?

In many cases, the integration is not easy in an analytical method.

The Monte Carlo Integration method is a numerical integration method.

Let’s think about the below example. MCI1


The goal of this integration is to find the area of pink region.

The key idea of the Monte Carlo integration is to find \hat{f}} to represent f. See below.

MCI2Then, How can we find the \hat{f}} ? the Monte Carlo Integration method uses “Expectation method” (Average) See below



With the random sampling method, we can get the \hat{f} by calculating the mean value.

This is a very useful way especially for the calculation of Bayesian posterior.


The below is an example of Monte Carlo Integration.

I will solve this problem  \int^2_{-1}x dx

>> N=10000;
>> 3*sum(rand(N,1)*3-1)/N

ans =


Here \hat{f} is < sum(rand(N,1)*3-1)/N > and the range of the integration is 3.

Then, good luck

For more detail, I recommend to read the below article.



I am Youngmok Yun, and writing about robotics theories and my research.

My main site is, and Korean ver. is


Leave a Reply