montecarlo

2
Monte Carlo Method for Finding Pi Imagine a square of side d, and a circle inscribed in it - see right Suppose we throw darts at the square - randomly, so they hit the square 'evenly'. What fraction would lie within the circle? The area of the square is d * d The area of the circle is PI * d * d / 4 So the probability a dart will land in the circle is PI / 4 Program result 3.13892 In the program, we We choose a random The center of the xd is x - 0.5, and By Pythagoras the the square root of If this is less th The program does t 4 times the fracti Start Program x y 0.5 0.5 1.0 1.0 xd + + + +

Upload: wilson-rojas-bayona

Post on 15-Sep-2015

215 views

Category:

Documents


2 download

DESCRIPTION

metodo de monte carlo.

TRANSCRIPT

Sheet1Monte Carlo Method for Finding PiImagine a square of side d, and a circle inscribed in it - see rightSuppose we throw darts at the square - randomly, so theyhit the square 'evenly'. What fraction would lie within the circle?The area of the square is d * dThe area of the circle is PI * d * d / 4So the probability a dart will land in the circle is PI / 4Program result3.13892In the program, we take the side of the square to be 1We choose a random point at (x,y)The center of the circle is at (0.5, 0.5)xd is x - 0.5, and similarly for ydBy Pythagoras the distance of the point from the center isthe square root of xd squared plus yd squaredIf this is less than 0.5, the point is inside the circle.The program does this 100000 times, and displays4 times the fraction in the circle - an estimate of PI

xy0.50.51.01.0xd++++++++++

Sheet2

Sheet3