Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I just need the code for this 2.4. [60 pts] Putting All Together While the textbook provides solutions and simple implementations to the previous problems,

image text in transcribedI just need the code for this

2.4. [60 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 1-3. Your task is to implement a function that computes and prints the required input parameters for each algorithm, given an error tolerance err_tol (a floating-point value between 0 and 1 ). E.g., if err_tol is 0.001, how many sides does the Archimedes algorithm need to produce an error of 0.001 or smaller? Recall that an accurate value of is available through the math . pi constant, but keep in mind that the smaller the value for err_tol, 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 1, 2, and 3, e.g., import arch. \[ \text { def al1 pi (err_tol: float) }>\text { list: } \] Example. These are the results as printed on a proposed solution to this problem. \$>p print (al1 pi (0.1) ) Archimedes: num sides =8 (Differs by 0.08012519466907486 ) Wallis: num pairs =8 (Differs by 0.0910026575342835 ) Monte Carlo: num_darts =20 (Differs by 0.05840734641020706 ) [8, 8, 20] Notice that when you run your code repeatedly with the same err_tol input, you get the same values for Archimedes and Wallis (i.e., those functions are deterministic). Still, you may get different answers for Monte Carlo (a non-deterministic function). The Monte Carlo produces different results because it uses pseudo-random 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 pseudo-random number generator with a fixed seed first (use 42 as your seed) before calling your mc.pi_mc function, e.g., random. seed (42). Seeding the random number generator is a common technique for testing non-deterministic computations. What to submit: Upload al1 pi.py on Coding Rooms

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

Database Systems Design Implementation And Management

Authors: Peter Rob, Carlos Coronel

3rd Edition

0760049041, 978-0760049044

More Books

Students also viewed these Databases questions

Question

9. Understand the phenomenon of code switching and interlanguage.

Answered: 1 week ago