Monte Carlo Integration
1. Monte Carlo integration
In this lesson, we will study how simulation can help in calculus via Monte Carlo integration. Monte Carlo integration is a numerical integration technique that utilizes the power of random numbers. For functions with just a single variable, Monte Carlo integration might seem inefficient. However, it's the method of choice as the number of dimensions becomes large. It's a relatively simple and intuitive process, let's try to understand it with a simple example.2. Definite integration
Consider a simple curve: x squared. You are interested in finding the area under this curve between x equals 1 and x equals 2. Solving by hand, you evaluate this as x cubed divided by three with limits 1 to 2, giving us 7 divided by 3 or 2.333. Now let's take a Monte Carlo integration approach to this same problem.3. Monte Carlo integration
The Monte Carlo integration approach can be boiled down to a three step procedure. First calculate the overall area by looking at the limits of the function. For a simple function of one variable, this area will be in the form of a rectangle. Next, randomly sample points within this rectangle. Next count the fraction of points below the curve. Finally, multiply this fraction by the overall area. Let's put this approach to work for our x-squared function. As we can see in the figure on the right, the total area of the rectangle is 4. Let's see how we can calculate this integral step-by-step.4. Monte Carlo integration
In the first step, we need to find the limits of the function. Looking at the integral, we see that x goes from 1 to 2. Additionally the y limits go from 0 to 4 giving us an overall area of 4.5. Monte Carlo integration
Next we visualize this rectangle with the curve. Now we can start randomly sampling points in this rectangle. Since we sample randomly, the points can fall anywhere in this rectangle. We sample a large number of points.6. Monte Carlo integration
Finally we count the fraction of points below the curve and multiply by overall area. If we sample say, 5,000 points, we get an answer of 2.303 which is pretty close to the actual answer of 2.333. Increasing the number of points we sample results in more accurate results. And it's that simple, this is the main idea behind Monte Carlo integration. Although this technique might seem overly complicated for evaluating simple integrals, it scales very well to multidimensional functions, which are very difficult to handle otherwise. This technique has applications in areas like particle physics and computational biology.7. Let's practice!
With that in mind, let's work through some examples. We will first code up a function to evaluate a simple integral similar to the one we worked through in this video. We will then see a very useful application of this technique for computing the value of pi. Time to practice!Create Your Free Account
or
By continuing, you accept our Terms of Use, our Privacy Policy and that your data is stored in the USA.