$30
CECS 451
Assignment 7
Total: 20 Points
General Instruction
Submit uncompressed file(s) in the Dropbox folder via BeachBoard (Not email).
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