Answered step by step
Verified Expert Solution
Question
1 Approved Answer
In this project, you will approximate Pi using several methods described in Chapter 2 of the textbook. You must submit your work by 1 1
In this project, you will approximate Pi using several methods described in Chapter of the
textbook.
You must submit your work by : pm on the due date there will be no extensions.
By completing this project, you will gain
practice implementing three algorithms for approximating Archimedes Wallis, and
Monte Carlo
practice following API requirements function signatures
experience using turtle graphics to visualize the Monte Carlo solution method
practice importing modules and functions from Python Standard Library math random
and your code different parts of this project
some knowledge of deterministic vs nondeterministic algorithms
practice Python functions with different return types, side effects, bool, selection
statements, loops, and strings
When writing Python code, follow the PEP Use whitespace between operators and
operands, use descriptive variable names, and add appropriate incode comments why not
what Do diligent parameter checking, eg do not assume that your function will receive a
positive int argument because you expect a positive int.
How to succeed:
Start early
Go to office hours
Ask questions on Discord or email.
All problems in this project are based on PPC Ch Make sure
You may have other helper methods called from the required functions
Include docstring documentation for all the required functions
Instructions
pts The Archimedes Method
Requirements: Implement the Archimedes method Sec in PPC using the following
function signature. In your function, return the computed approximation of do not change
the name or type of argument and return value Feel free to use the book version or come up
with your own.
def piarchnumsides: int float
Function signatures are informative; they contribute to documenting your code. Signatures
describe the input parameters' data types and the return value. Signatures do not perform any
data type validation.
What to submit: Upload arch.py on Coding Rooms.
pts The Wallis Method
Requirements: Implement the Wallis approximation method Sec in PPC using the
following function signature. In your function, return the computed approximation of do not
change the name or type of argument and return value Feel free to use the book version or
come up with your own.
def piwallisnumpairs: int float
What to submit: Upload wallis.py on Coding Rooms.
pts Monte Carlo Simulation
Requirements: Implement the Monte Carlo approximation of Sec in PPC using the
following function signature. In your function, return the computed approximation of do not
change the name or type of argument and return value Feel free to use the book version or
come up with your own.
Since you use pseudorandom numbers, you may get different answers each time you call the
function, so initialize random with a fixed seed see example in Part Use as the random
seed in all experiments so all our results match read https:tinyurlcomUQLUE
def pimcnumdarts: int float
What to submit: Upload mcpy on Coding Rooms.
pts Putting All Together
While the textbook provides solutions and simple implementations to the previous problems, in
this part, you get to design a method for evaluating the different approaches implemented in
Parts
Your task is to implement a function that computes and prints the required input parameters
for each algorithm, given an error tolerance errtol a floatingpoint value between and
Eg if errtol is how many sides does the Archimedes algorithm need to produce an
error of or smaller?
Recall that an accurate value of is available through the math.pi constant, but remember that
the smaller the value for errtol, the longer each method will take. Feel free to implement
any helper functions you need.
Requirements: Function signature input one float number and return a list of three values.
Ensure you import the Python modules you created for Parts and eg import arch.
def allpierrtol: float list:
Example. These are the results as printed on a proposed solution to this problem.
printallpi
Archimedes: numsides Differs by
Wallis: numpairs Differs by
Monte Carlo: numdarts Differs by
When you run your code repeatedly with the same errtol input, you get the same values for
Archimedes and Wallis ie those functions are deterministic Still, you may obtain different
answers for Monte Carlo a nondeterministic function The Monte Carlo produces different
results because it uses pseudorandom numbers for the darts' positions and gets different sets of
points with every run.
To ensure you get the same result every time you run, you can initialize the pseudorandom
number generator with a fixed seed first use as your seed before calling your mcpimc
function, eg
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