This action might not be possible to undo. Are you sure you want to continue?

# Calculation of Pi Using the Monte Carlo Method

Presented by: Monzur Morshed Habibur Rahman

TigerHATS

www.tigerhats.org

**TigerHATS - Information is power
**

The International Research group dedicated to Theories, Simulation and Modeling, New Approaches, Applications, Experiences, Development, Evaluations, Education, Human, Cultural and Industrial Technology

**Monte Carlo Methods
**

Stochastic techniques - based on the use of random numbers and probability statistics to investigate problems Large system ->random configurations, data-> describe the whole system "Hit and miss" integration is the simplest type

Calculation of Pi Using the Monte Carlo Method

If you are a very poor dart player, it is easy to imagine throwing darts randomly at Figure 2, and it should be apparent that of the total number of darts that hit within the square, the number of darts that hit the shaded part (circle quadrant) is proportional to the area of that part. In other words, Source: http://www.chem.unl.edu/zeng/joy/mclab/mcintro.html

Calculation of Pi Using the Monte Carlo Method

Source: http://www.chem.unl.edu/zeng/joy/mclab/mcintro.html

Monte Carlo method applied to approximating the value of π

Source: http://en.wikipedia.org/wiki/File:Pi_30K.gif

Calculation of Pi Using the Monte Carlo Method Randomly select values for x and y 0 <= x,y <=1 Pi = 4 . (inside points / total points)

Source: http://www.modula2.org/projects/pi_by_montecarlo/est_pi.gif

**Calculation of Pi Using the Monte Carlo Method
**

The algorithm in pseudo-code is given in next slide where for simplicity we have chosen the radius to be r=1 and examine only the first quadrant. Choosing only the first quadrant does not change the ratio. The code below does the following: - Choose 1000 or any say 100000 dots randomly. - If the dot lands within the circle count the dot by increasing the variable “circleArea” by 1. - At the end compare the number of dots within the circle with the total number of dots.

Pseudo-code

01 02 03 04 05 06 07 08 09 10 circleArea = 0 squareArea = 0 for(i=1 to 1000): x = random value from [0,1] y = random value from [0,1] if (x,y) within the circle: circleArea = circleArea + 1 squareArea = squareArea + 1 pi = 4.0*circleArea/squareArea print pi

Pseudo-code

To check whether (x,y) lies within the circle (including the circumference) use the following function: 01 02 03 04 05 withinCircle(x,y) if(x^2+y^2<=1): return True else: return False

Thank You.