Available

CS 3341 HW # 7 (SOLUTION)
1. Estimating the value of π using Monte Carlo simulation: Consider a square centered at
(0.5, 0.5) whose area is equal to one. Also, suppose that a circle with center (0.5, 0.5) and
radius 0.5 is inscribed in this square, as demonstrated in the following figure.
(a) Suppose E denotes the event E = {A randomly chosen point in the square falls inside the
circle}. Prove that P(E) = π/4.
P(E) = area of the circle/area of the square = π/4
(b) This suggests that π = 4 × P(E). So, we can estimate the value of π if we can estimate
P(E). This probability can be estimated using Monte Carlo simulation by randomly
generating a large number of points (say, N) inside the square and finding the proportion
of points that fall inside the circle. Implement the following algorithm with N = 10,000 to
get an estimate.
1
Step 1: Generate N x-coordinates X1, X2, …, XN as independent draws from a Uniform
(0, 1) distribution.
Step 2: Generate N y-coordinates Y1, Y2, …, YN as independent draws from a Uniform
(0, 1) distribution.
Step 3: Now we have randomly generated N points, (X1, Y1), (X2, Y2), …., (XN, YN),
inside the square. Find the proportion of these points that fall in the circle. A point (X, Y)
is inside the circle if (X – 0.5)2 + (Y – 0.5)2 ≤ 0.25.
When I implemented this algorithm in R (www.r-project.org) – a freely available
statistical software package, I got P(E) ≈ 0.7856, and hence π ≈ 4(0.7856) = 3.1424.
The correct value of π = 3.141593.
We can get a more accurate estimate by using a larger N.
R code:
x <- runif(10000)
# generates x coordinates
y <- runif(10000)
# generates y coordinates
prop <- mean(1*( ((x-0.5)^2 + (y - 0.5)^2) <= 0.25))
# finds proportion of points in circle
pi.val <- 4*prop
# estimated value of pi
2. A system consists of two subsystems connected in series as shown in the following diagram.
A
C
B
D
Each subsystem consists of two components connected in parallel. The AB subsystem fails when
both A and B have failed. The CD subsystem fails when both C and D have failed. The whole
system fails as soon as one of the two subsystems fails. Assume that lifetimes of the components,
in months, have the following distributions: A: TA ~ Exponential (1), B: TB ~ Exponential (0.1),
TC ~ Exponential (0.2), D: TD ~ Exponential (0.2).
2
(a) Find the random variables that represent the lifetimes of AB and CD subsystems, and the
lifetime of the whole system.
TAB = lifetime of AB subsystem = max (TA, TB).
TCD = lifetime of CD subsystem = max (TC, TD).
TSYS = lifetime of whole system = min (TAB, TCD).
(b) Estimate the average system lifetime using Monte Carlo simulation. Take N = 10,000.
Using R, E[TSYS] ≈ 4.75 months
R code:
t.a
t.b
t.c
t.d
<<<<-
rexp(10000,
rexp(10000,
rexp(10000,
rexp(10000,
1)
0.1)
0.2)
0.2)
#
#
#
#
A
B
C
D
lifetimes
lifetimes
lifetimes
lifetimes
t.ab <- pmax(t.a, t.b)
t.cd <- pmax(t.c, t.d)
# AB lifetimes
# CD lifetimes
t.sys <- pmin(t.ab, t.cd)
# System lifetimes
mean(t.sys)
# mean of system lifetimes
(c) Estimate the probability that the AB subsystem fails before the CD subsystem fails, using
Monte Carlo simulation.
We want P(TAB < TCD).
From our simulated lifetimes, the proportion of times TAB < TCD = 0.465 ≈ P(TAB < TCD).
R code:
mean(1*(t.ab < t.cd))
# proportion of times t.ab < t.cd
3