Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Problem 5 We want to use random numbers to estimate the value of a. Consider a unit circle (that is a circle around the origin
Problem 5 We want to use random numbers to estimate the value of a. Consider a unit circle (that is a circle around the origin of radius 1) and consider the smallest square with sides parallel to the axes that contains that circle. Write code below to generate n random vectors that are uniformly distributed over the area of the square. Hint: Recall, that a circle of radius r has area ar2. What is the area of the smallest square with sides parallel to the axes that contains the unit circle? What is the probability that a random variable distributed randomly on this square lands in the unit circle? Use your simulated random vectors to estimate the value of a for different values of n. Explain how your code works: what are you counting and why is it reasonable to use this count as an estimate for a? Make sure to comment your code well enough so that a reader can follow the steps in your description and find each one reflected in the code. Your code should ask the user to input the value of n and output a statement that reads: "For n=__ iterations, the estimate of the pi is __" where both blanks should be filled in with meaningful values derived from your code. Hint: To repeat the same task n times in Python you could use a for-loop. See top for general syntax
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started