# EE 381 Assignment 04 – Central Limit Theorem: Simulate RVs with Exponential Distribution solution

\$25.00

Category:

## Description

0. Introduction and Background Material
0.1. Simulate a R.V. with Uniform Probability Distribution
The Python function “numpy.random.uniform(a,b,n)” will generate n random
numbers with uniform probability distribution in the open interval [a b, ) . The PDF
of a random variable uniformly distributed in [a b, ) is defined as following:
1 , ( ) ( )
0, otherwise
axb
f x b a

 ≤ ≤ =  −

; and
0,
( ) ( ) () , ( )
1,
x a
x a PX x Fx a x b
b a
x b
 < 
 − ≤ = =  ≤ < − 

 ≥
It is noted that the mean and variance of a uniformly distributed random variable X are
given by:
2
2 ( ) E( ) ; Var( ) 2 12 X X
a b b a X X µ σ
+ − = = = =
EE 381 Project: Central Limit Theorem Dr. Chassiakos — Page 2
0.2. Simulate a R.V. with Exponential Probability Distribution
The Python function “numpy.random.exponential(a,n)” will generate n
random numbers with exponential probability distribution.
The PDF of a random variable exponentially distributed is defined as following:
1 1 exp( ), 0 (; )
0, 0
T
t t
f t
t
β β β

 − ≥ = 

 <
From the above definition, the CDF of T is found as:
0, 0
( ) () 1 1 exp( ), 0
t
PT t Ft
t t
β
 <  ≤= =  −− ≥ 

It is noted that the mean and variance of the exponentially distributed random variable
T are given by:
2 2 E( ) ; Var( ) T T = = µβ σβ T T = =
0.3. Central Limit Theorem
If 1 2 , , XX X  n are independent random variables having the same probability
distribution with mean µ and standard deviation σ , consider the sum
n n 1 2 S XX X =++ .
This sum n S is a random variable with mean n S µ µ = n and standard deviation
n S σ σ= n .
The Central Limit Theorem states that as n → ∞ the probability distribution of the
R.V. n S will approach a normal distribution with mean n µS and standard deviation
n σ S , regardless of the original distribution of the R.V. 1 2 , , XX X  n . The PDF of the
normally distributed R.V. n S is given by:
2
2
1 ( ) ( ) exp{ } 2 2
n
n n
S
n
S S
x
f s µ
σ π σ
− = −
EE 381 Project: Central Limit Theorem Dr. Chassiakos — Page 3
PROBLEMS
1. The Central Limit Theorem
Central Limit Theorem.
Consider a collection of books, each of which has thickness W . The thickness W is a
RV, uniformly distributed between 1 and 3 cm. The mean and standard deviation of
the thickness will be:
2 1 3 (3 1) 2 2; 0.33; 0.57 2 12 µσ σ ww w
+ − = = = = = .
These books are piled in stacks of n =1,5,10, or 15 books. The width n S of a stack of
n books is a RV (the sum of the widths of the n books). This RV has a mean
n S w µ µ = n and a standard deviation of n S w σ σ= n .
Perform the following simulation experiments, and plot the results.
a) Make n =1and run N =10,000 experiments, simulating the RV 1 S W= .
b) After the N experiments are completed, create and plot a probability histogram
of the RV S
c) On the same figure, plot the normal distribution probability function and
compare the probability histogram with the plot of f x( )
2
2
1 ( ) ( ) exp{ } 2 2
S
S S
x f x µ
σ π σ
− = −
d) Make n = 5 and repeat steps (a)-(c)
e) Make n =10 and repeat steps (a)-(c)
f) Make n =15 and repeat steps (a)-(c)
SUBMIT a report following the guidelines as described in the syllabus.
The report should include, among the other requirements:
• The four histograms for n = {1,5,10,15} and the overlapping normal
probability distribution plots.
• The Python code, included in an Appendix.
• Make sure that the graphs are properly labeled.
An example of the graph for n = 2 is shown below.
The code below provides a suggestion on how to generate a bar graph for a
continuous random variable X , representing the total bookwidth, when
n = 2 . Note that X has already been calculated.
The code shows the bar graph plotting only. It does not show the calculations
for X s and it does not show the plotting of the Gaussian function.
EE 381 Project: Central Limit Theorem Dr. Chassiakos — Page 4
Note that the value of ”barwidth” is adjusted as the number of bins
changes, to provide a clear and understandable bar graph.
Also note that the ”density=True” parameter is needed to ensure that the
total area of the bargraph is equal to 1.0.
# X is the array with the values of the RV to be plotted
a=1; b=3; # a=min bookwidth ; b=max bookwidth
nbooks=2; nbins=30; # Number of books ; Number of bins
edgecolor=’w’; # Color separating bars in the bargraph
#
# Create bins and histogram
bins=[float(x) for x in linspace(nbooks*a, nbooks*b,nbins+1)]
h1, bin_edges = histogram(X,bins,density=True)
# Define points on the horizontal axis
be1=bin_edges[0:size(bin_edges)-1]
be2=bin_edges[1:size(bin_edges)]
b1=(be1+be2)/2
barwidth=b1[1]-b1[0] # Width of bars in the bargraph
close(‘all’)
#
fig1=plt.figure(1)
plt.bar(b1,h1, width=barwidth, edgecolor=edgecolor)
EE 381 Project: Central Limit Theorem Dr. Chassiakos — Page 5
2. Exponentially Distributed Random Variables
Exponentially Distributed RVs
The goal is to simulate an exponentially distributed R.V. (T ), given by the
following PDF:
2exp( 2 ), 0 ( ) 0, 0 T
t t
f t t
 − ≥ = 
 <
1. Perform N =10,000 experiments and generate the probability histogram of the
random variable T . Plot the histogram of the RV T .
2. On the same graph, plot the function 2exp( 2 ), 0 ( ) 0, 0
x x
g x
x
 − ≥ = 
 <
and compare to the experimentally generated histogram.
SUBMIT a report following the guidelines as described in the syllabus. The
report should include, among the other requirements:
• the histogram of the RV T ;
• the graph of the function g x( ) overlaying the histogram on the same plot;
• the Python code.
3. Make sure that the graph is properly labeled.
EE 381 Project: Central Limit Theorem Dr. Chassiakos — Page 6
3. Distribution of the Sum of RVs
This problem involves a battery-operated critical medical monitor. The lifetime (T )
of the battery is a random variable with an exponentially distributed lifetime. A
battery lasts an average of τ = 45days. Under these conditions, the PDF of the
1 1 exp( ), 0 ( ; ) where 45
0, 0
T
t t
f t
t
β β β β

 − ≥ =  =

 <
As mentioned before, the mean and variance of the random variable T are:
2 2 ; µβ σβ T T = =
When a battery fails it is replaced immediately by a new one. Batteries are
purchased in a carton of 24. The objective is to simulate the RV representing the
lifetime of a carton of 24 batteries, and create a histogram. To do this, follow the
steps below.
a) Create a vector of 24 elements that represents a carton. Each one of the 24
elements in the vector is an exponentially distributed random variable (T ) as
shown above, with β = 45. Use the same procedure as in the previous problem
to generate the exponentially distributed random variable T .
b) The sum of the elements of this vector is a random variable (C ), representing
the life of the carton, i.e.
CTT T =++ 1 2 24 
where each , 1,2, 24 T j j =  is an exponentially distributed R.V. Create the R.V.
C , i.e. simulate one carton of batteries. This is considered one experiment.
c) Repeat this experiment for a total of N=10,000 times, i.e. for N cartons. Use the
values from the N=10,000 experiments to create the experimental PDF of the
lifetime of a carton, f c( ).
d) According to the Central Limit Theorem the PDF for one carton of 24 batteries
can be approximated by a normal distribution with mean and standard deviation
given by:
24 24 ; 24 24 µ µ β σσ β C T = = C T = =
Plot the graph of a normal distribution with
mean = µC and (standard deviation) = σ C ,
over plot of the experimental PDF on the same figure, and compare the results.
e) Create and plot the CDF of the lifetime of a carton, F c( ) . To do this use the
Python “numpy.cumsum” function on the values you calculated for the
experimental PDF.
EE 381 Project: Central Limit Theorem Dr. Chassiakos — Page 7
1. Find the probability that the carton will last longer than three years, i.e.
P S( 3 365) 1 ( 3 365) 1 (1095) >× =− ≤× =− P S F . Use the graph of the CDF F t( ) to
estimate this probability.
2. Find the probability that the carton will last between 2.0 and 2.5 years (i.e.
between 730 and 912 days): PS F F (730 912) (912) (730) ≤≤ = − . Use the graph of
the CDF F t( ) to estimate this probability.
3. SUBMIT a report following the guidelines as described in the syllabus.
The report should include, among the other requirements:
• The numerical answers using the table below. Note: You will need to replicate the
table, in order to provide the answer in your report. Points will be taken off if you do not use
the table.
• The PDF plot of the lifetime of one carton and the corresponding normal
distribution on the same figure.
• The CFD plot of the lifetime of one carton
• Make sure that the graphs are properly labeled.
• The code in an Appendix.
QUESTION ANS.
1. Probability that the carton will last longer than three years
2. Probability that the carton will last between 2.0 and 2.5 years