
Notes on Computer Assignment 1
Math 5040 โ Fall 2002
See the attached program simexp.c for a C program which generates 100 exponential(1)
random variables and counts the fraction below 1 and above 2.
Executing this program yields the following output:
fraction less than 1 is 0.640000
fraction greater than 2 is 0.160000
Let us compare these proportions with the probabilities
๎
{X < 1}and
๎
{X > 2}:
๎
{X < 1}=Z1
0
eโx
=โeโx๎
๎
1
0
= 1 โeโ1
= 0.632
๎
{X > 2}=eโ2
= 0.135
Notice that we have estimated p1=
๎
{X < 1}by
หp1=1
100
100
X
i=1
1{Xi<1},
where X1,...,X100 are i.i.d. exponential random variables.
What is the variance in our estimate?
Var(p1) = 1
1002100 Var(1{X1<1})
=1
100(0.632)(0.368)
= 0.00233
Thus the standard deviation of หp1is 0.0482. Clearly หp1has expectation equal to p1.
Thus our simulation makes sense: our estimate fell within a standard deviation of its mean.
See the attached C program normal.c, which generates 100 normal r.v.s by the rejection
method, and counts the fraction in (โ1,1).
The output of the program is
fraction of 100 independent normals in (-1,1) is 0.72
By comparison, the probability a standard normal is in (โ1,1) is about 0.68.
1