Upload
tigerhats
View
250
Download
3
Embed Size (px)
DESCRIPTION
Calculation of Pi Using the Monte Carlo Method
Citation preview
Calculation of Pi Using the Monte Carlo
Method
Presented by:
Monzur MorshedHabibur Rahman
TigerHATSwww.tigerhats.org
The International Research group dedicated to Theories, Simulation and
Modeling, New Approaches, Applications, Experiences, Development, Evaluations, Education, Human, Cultural and Industrial Technology
TigerHATS - Information is power
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
Monte Carlo Methods
Calculation of Pi Using the Monte Carlo Method
Source: http://www.chem.unl.edu/zeng/joy/mclab/mcintro.html
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,
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
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.
Calculation of Pi Using the Monte Carlo Method
01 circleArea = 002 squareArea = 003 for(i=1 to 1000):04 x = random value from [0,1]05 y = random value from [0,1]06 if (x,y) within the circle:07 circleArea = circleArea + 108 squareArea = squareArea + 109 pi = 4.0*circleArea/squareArea10 print pi
Pseudo-code
01 withinCircle(x,y)02 if(x^2+y^2<=1):03 return True04 else:05 return False
To check whether (x,y) lies within the circle (including the circumference) use the following function:
Pseudo-code
Thank You.