Professional Documents
Culture Documents
TigerHATS
www.tigerhats.org
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
Source: http://www.chem.unl.edu/zeng/joy/mclab/mcintro.html
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
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.