Description
1. Implement a program to estimate π using the simulation method.
(a) The program should generate n random points of (x, y) where 0 ≤ x < 1 and
0 ≤ y < 1 for n ∈ {103
, 104
, 105
, 106}.
(b) You can use math.pi to compute error rates.
(c) (10 points) Please follow the output format. Note that the estimated π and the
error rates may be different. (Fix precision using “0:.nf”.format)
n = 10 ^ 3 pi = 3.096000 error = 1.4513 %
n = 10 ^ 4 pi = 3.136800 error = 0.1526 %
n = 10 ^ 5 pi = 3.145280 error = 0.1174 %
n = 10 ^ 6 pi = 3.140568 error = 0.0326 %
You can use the formula
error(%) = |
π − π
′
π
| × 100,
where π
′
is the estimation.
(d) (10 points) For n = 104
, draw a scatter plot as Figure 1, i.e., blue color for dots
whose distances from the origin (0, 0) are less than 1, otherwise red color.
(e) Submit pi.ipynb.
CECS 451 Assignment 7 – Page 2 of 2
Figure 1: Estimating π using simulation
Custom Work, Just for You!
Can’t find the tutorial you need? No worries! We create custom, original work at affordable prices! We specialize in Computer Science, Software, Mechanical, and Electrical Engineering, as well as Health Sciences, Statistics, Discrete Math, Social Sciences, Law, and English.
Custom/Original Work Essays cost as low as $10 per page.
Programming Custom Work starts from $50.
Get top-quality help now!