Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please write in Python. Compute T by a Monte Carlo Method 3 points Monte Carlo methods are any numerical methods determined by the use of

image text in transcribed

Please write in Python.

Compute T by a Monte Carlo Method 3 points Monte Carlo methods are any numerical methods determined by the use of random numbers in processes-like radioactive decay of a particle or the likelihood of a single molecule to react. (Note that the physical processes aren't called "Monte Carlo", only the numerical methods using random numbers.) We will use a random method, called Buffon's Needle, to estimate the value of ?. Consider a circle inscribed inside of a square. If the circle has unit radius, r-1, then its area A ?. The square in which it is inscribed has vertices (-1,-1), (+1,-1). (+1, +1), (-1, +1) with area A 2x If you consider throwing a dart at the square, the probability that it lands inside of the circle is .We can thus use neircle as a proxy for Acircle and treat the square similarly Compose a function mc-pi( n ) to estimate the value of ? using the Buffon's Needle method. n describes the number of points to be used in the simulation. mc_pi should return its estimate of the value of ? as a float . Your process should look like the following: 1. Prepare an array of coordinate pairs xy. This should be of shape n,2) selected from an appropriate distribution (see notes 1 and 2 below). 2. Calculate the number of coordinate pairs inside the circle's radius. (How would you do this mathematically? Can you do this in NumPy without a loop?-although a loop is okay.) 3. Calculate the rati 4. Return this estimate of ? 5. You may find it edifying to try the following values of n , and compare each result to the value of math, pi : 1e, 100 , 10ee? 1e4. 1e5, 1e6 , 1e7, 1e8How does the oA, which implies (following the development above), 4 Ragesace Aue computational time vary? How about the accuracy of the estimate of ? You will need to consider the following notes 1. Which kind of distribution is most appropriate for randomly sampling the entire area? (Hint: if we could aim, it would be the normal distribution-but we shouldn't aim in this problem!) 2. Since numpy.random distributions accept sizes as arguments, you could use something like np. random.distribution n, 2) to generate coordinate pairs (in the range [0,1) which you'll then need to transform)-but use the right distribution! Given a distribution from [0, 1), how would you transform it to encompass the range [-1,1)? (You can do this to the entire array at once since addition and multiplication are vectorized operations.) Your submission should include a function mc pi( n ) Compute T by a Monte Carlo Method 3 points Monte Carlo methods are any numerical methods determined by the use of random numbers in processes-like radioactive decay of a particle or the likelihood of a single molecule to react. (Note that the physical processes aren't called "Monte Carlo", only the numerical methods using random numbers.) We will use a random method, called Buffon's Needle, to estimate the value of ?. Consider a circle inscribed inside of a square. If the circle has unit radius, r-1, then its area A ?. The square in which it is inscribed has vertices (-1,-1), (+1,-1). (+1, +1), (-1, +1) with area A 2x If you consider throwing a dart at the square, the probability that it lands inside of the circle is .We can thus use neircle as a proxy for Acircle and treat the square similarly Compose a function mc-pi( n ) to estimate the value of ? using the Buffon's Needle method. n describes the number of points to be used in the simulation. mc_pi should return its estimate of the value of ? as a float . Your process should look like the following: 1. Prepare an array of coordinate pairs xy. This should be of shape n,2) selected from an appropriate distribution (see notes 1 and 2 below). 2. Calculate the number of coordinate pairs inside the circle's radius. (How would you do this mathematically? Can you do this in NumPy without a loop?-although a loop is okay.) 3. Calculate the rati 4. Return this estimate of ? 5. You may find it edifying to try the following values of n , and compare each result to the value of math, pi : 1e, 100 , 10ee? 1e4. 1e5, 1e6 , 1e7, 1e8How does the oA, which implies (following the development above), 4 Ragesace Aue computational time vary? How about the accuracy of the estimate of ? You will need to consider the following notes 1. Which kind of distribution is most appropriate for randomly sampling the entire area? (Hint: if we could aim, it would be the normal distribution-but we shouldn't aim in this problem!) 2. Since numpy.random distributions accept sizes as arguments, you could use something like np. random.distribution n, 2) to generate coordinate pairs (in the range [0,1) which you'll then need to transform)-but use the right distribution! Given a distribution from [0, 1), how would you transform it to encompass the range [-1,1)? (You can do this to the entire array at once since addition and multiplication are vectorized operations.) Your submission should include a function mc pi( n )

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Genomes Browsers And Databases Data Mining Tools For Integrated Genomic Databases

Authors: Peter Schattner

1st Edition

0521711320, 978-0521711326

More Books

Students also viewed these Databases questions

Question

Perform an Internet search. Discuss a company that uses EPLI.

Answered: 1 week ago

Question

How do you feel about employment-at-will policies? Are they fair?

Answered: 1 week ago