Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Python question: Requriements Submit only the files requested Print all floats to 2 decimal points unless stated otherwise Restrictions No global variables may be used

Python question:
Requriements
Submit only the files requested
Print all floats to 2 decimal points unless stated otherwise
Restrictions
No global variables may be used
Your program must have at least 1 user defined function
Description
For this problem you will be implementing a Monte Carlo method for the estimation of pi. Imagine that you have a circle of radius 1 whose center is at (0,0) surrounded by a square with sides of length 2 as pictured below
If we randomly choose points within the square the probability of a point being inside the circle is proportional to the area of the square that it occupies. This means that
Solving for pi we have
The probability for pi can be approximiated by picking a large number of points between [-1, 1] and counting the number that are inside the circle. The number of points inside the circle divided by the the total number of points picked is the probability of being inside the circle
Report your answer to 3 digits after the decimal place
Assumptions
Input will always be valid
Valid values for inputs
Seed: an integer
Number iterations: an integer greater than 0
Randomness
In order to match the outputs on Mimir you will need to make calls to functions in the random module in the exact order that I do
o First make sure to seed the random number generator using random.seed
o Use random.uniform to generate the values
o First generate a random number between [-1, 1] for the x axis
o Then generate a random number between [-1,1] for the y axis
o Numbers that fall exactly on the edge of the circle are considered to be inside the circle
Examples
Example 1
Enter the seed for the random number generator: 4
Enter the number of iterations to run: 10
The value of pi is 2.800.
Example 2
Enter the seed for the random number generator: -7
Enter the number of iterations to run: 2
The value of pi is 4.000.
Example 3
Enter the seed for the random number generator: -7
Enter the number of iterations to run: 10000
The value of pi is 3.140.
image text in transcribed
image text in transcribed
Requriements Submit only the files requested Print all floats to 2 decimal points unless stated otherwise Restrictions No global variables may be used Your program must have at least 1 user defined function Description For this problem you will be implementing a Monte Carlo method for the estimation of pi. Imagine that you have a circle of radius I whose center is at (0,0) surrounded by a square with sides of length 2 as pictured below (0,0) 0,-1) If we randomly choose points within the square the probability of a point being inside the circle is proportional to the area of the square that it occupies. This means that Probabilir Areas22 4 Solving for pi we have pr=Probabiliyhadean'4 The probability for pi can be approximiated by picking a large number of points between, and counting the number that are inside the circle. The number of points inside the circle divided by the the total number of points picked is the probability of being inside the circle Probabliny suucemmber of points picked number ts in thecircle

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

Pro Database Migration To Azure Data Modernization For The Enterprise

Authors: Kevin Kline, Denis McDowell, Dustin Dorsey, Matt Gordon

1st Edition

1484282299, 978-1484282298

More Books

Students also viewed these Databases questions

Question

5. How do instructional objectives help learning to occur?

Answered: 1 week ago

Question

Why is the System Build Process an iterative process?

Answered: 1 week ago