montecarlo
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