Question: in python Monte Carlo - Area of Illinois 10 points Computing the area of objects that are odd shapes can be quite difficult. However, Monte

in python Monte Carlo - Area of Illinois 10 points Computing thearea of objects that are odd shapes can be quite difficult. However,in python

Monte Carlo - Area of Illinois 10 points Computing the area of objects that are odd shapes can be quite difficult. However, Monte Carlo simulation can be used to easily find the areas of objects that are odd shapes This problem will focus on using Monte Carlo simulation to compute the area of an object that is an odd shape, specifically the state of Illinois. Consider this outline picture of the state of Illinois. This picture is adapted from one on Wikimedia, Write Python code that uses Monte Carlo simulation with this picture to estimate the area of the state of Illinois. Pixels in the picture that are black are inside of Illinois and pixels in the picture that are white are outside of Illinois. The size of the picture corresponds to a physical distance of 304 miles wide by 450 miles tall Your code will see a variable called img which is a numpy array containing the image data. The image is black and white -- the entries in img are either 0 or 255. If you wish to program this on your local machine, you will want to download the image and use scipy.misc. inread name) , where fname is a string of the file name. Note, you do not need to (and can't do that when submitting your code here. When submitting your code here, you should use the variable img which is already a numpy array with the image data. The random number generator is seeded in the startup code). You must use np. random, rand into to generate your random numbers. For each trial, you will need to generate a random integer col in the image array and another random integer row in the image array. They must be generated in this order, col first then row. See the example in the starter code below. Your code should produce a variable called area which is a float with the estimate of the area of Illinois (in square miles) obtained using Monte Carlo simulation. Use 10 trials (points) to determine the area To determine the accuracy of your simulation, you will use another method to get the area of Illinois. Count the number of black pixels in the image, and use this along with the information given above to get a more accuracte calculation of the area of Illinois. Using this value as the true solution, compute the relative error of the solution from the simulation. Store this value as relerror INPUT .img : 0 and 255 matrix, O representing points within Illinois OUTPUT . area: float with the estimate of Illinois (in square miles) obtained by Monte Carlo simulations Aeal value-Predicted val rel_error: Actual value

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!