Monte Carlo Approximation of Pi - Maple Help
For the best experience, we recommend viewing online help using Google Chrome or Microsoft Edge.

Online Help

All Products    Maple    MapleSim

Home : Support : Online Help : Math Apps : Probability and Statistics : Statistics : Monte Carlo Approximation of Pi

Monte Carlo Approximation of π

Main Concept

Monte Carlo methods are a class of computational algorithms that repeat random samplings to obtain numeric results. In this example, Monte Carlo simulation is used to randomly sample points from a Uniform distribution in order to approximate a value for π.


One way to estimate π is to compare the ratio of the area of a circle to the area of a square.



We begin by considering a circle inscribed in a unit square.

plots:-display plottools:-circle0,0,1,                 plottools:-curve1,1, 1,1, 1, 1, 1,1, 1,1

The area of the circle is: π r2=π 

The area of the unit square is: 22=4


The ratio of the area of the circle to the area of the square is then:

ratio=area of circlearea of square=π4

This can be rewritten as π = 4  ratio.


The task of computing the ratio of the circle to the area of the square can be done as follows:



We uniformly scatter points over the square. This is equivalent to randomly sampling points from a Uniform distribution between the minimum value 1 and the maximum value 1.


We count the total number of objects as well as the number inside of the square. We can note that if x2+y21, a given point falls inside the circle; otherwise, it falls outside.


The ratio of the two counts is an estimate for the ratio of the two areas. Multiplying this by 4 gives an estimate for π.


Adjust the number of points being plotted and see how it affects the approximation of π. Note that Monte Carlo simulation uses random sampling, so the estimate will not be exactly the same every time you run a simulation.


number of dots=


Points in Circle

Number of Dots

Points in CircleNumber of Dots

Estimated Value of π

Actual Value of π

More MathApps