Question: Using Python format! Activity 0: Pi via Monte Carlo For this activity, you are to implement the Monte Carlo The Monte Carlo method is a
Activity 0: Pi via Monte Carlo For this activity, you are to implement the Monte Carlo The Monte Carlo method is a way of finding approximate solutions to problems that cannot be precisely solved. A common example of such a problem is determining the value of pi. To compute the value of pi, we can do the following: "Let's consider the problem of estimating Pi by utilizing the Monte Carlo method. Suppose you have a circle inscribed in a square (as in the figure). The experiment simply consists of throwing darts on this figure completely at random (meaning that every point on the dartboard has an equal chance of being hit by the dart). How can we use this experiment to estimate Pi? The answer lies discovering the relationship between the geometry of the figure and the statistical outcome of throwing the darts Let's first look at the geometry of the figure. Let's assume the radius of the circle is Rthen the Area of the circle-Pi" R2 and the Area of the square = 4.R2 Now if we divide the area of the circle by the area of the square we get Pi/4 But, how do we estimate Pi by simulation? In the simulation, you keep throwing darts at random onto the dartboard. All of the darts fall within the square, but not all of them fall within the circle. Here's the key. If you throw darts completely at random, this experiment estimate the ratio of the area of the circle to the area of the square, by counting the number of darts in each. Our study of the geometry tells us this ratio is Pi/4. So, now we can estimate Pi as Pi = 4 x (Number of Darts in Circle) / (Number of Darts in Square)" The common approach to implementing this simulation involves computing a pair of x and y coordinates which range between [-1, 1 in each iteration and checking to see if that point is within a circle with a center at the origin and a radius of 1. If the point is within a circle, increment the counter that tracks the number of darts in a circle. But, I think it would be easier for you to generate x and y coordinates with a range of [0, 1 and check if the hypotenuse of this point with respect to the origin is less than 1. The advantage of this method is that we can simply use random.uniformO to compute two numbers between [0, 1] and then math.hypot(x, y) to compute the hypotenuse of this coordinate with respect to the origin and x-axis
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
