Professional Documents
Culture Documents
Exercise
Let random variable X be the outcome of rolling two six-sided dice then obtaining the sum.
1. (2 POINTS) Simulate X with M = 1000 trials. (Hint: Random variable X can be
decomposed into two experiments, X1 and X2, such that X = X1 + X2. You may use
the function sum)
2. (1 POINT) Plot the statistical PMF of X. For example, the probability of obtaining a 2
would be the number of trials that a 2 occurred divided by the total number of trials.
3. (1 POINT) Plot the theoretical PMF of X. (Hint: Functions that would be useful would
be length, stem, and figure).
4. (1 POINT) Compare the statistical PMF of X with the theoretical PMF.
5. (1 POINT) What would happen with different values of M?
6. (1 POINT) Compute for the statistical expectation of X and compare with the
theoretical expectation of X.
Part III. Simulating a Binomial Random Variable
Each trial (called a Bernoulli trial) in a binomial random variable consists of two outcomes:
success or failure. Each trial is independent from past and future trials, and the probability
of each outcome is constant throughout the experiment. The probability mass function is
defined as:
𝑛
𝑝𝑋 (𝑘) = ( ) 𝑝𝑘 (1 − 𝑝)𝑛−𝑘 , 𝑘 = 0, 1, 2, … , 𝑛
𝑘
where n is the number of trials, p is the probability of success, and k is the number of
successful trials.
Exercise
Consider the stochastic experiment discussed in Problem 01 of DC 03. Let X be the number
of hits.
1. (2 POINTS) Create a function binoRV with input parameters n (number of trials) and
p (probability of success), and output parameter x (the outcome of the experiment).
The function should simulate a single outcome of a binomial experiment (i.e. the
number of hits the marksman made). You may use a similar scheme as in Part II.
2. (1 POINT) Simulate the random variable X for M = 1000.
3. (1 POINT) Plot the statistical PMF of X.
4. (1 POINT) Plot the theoretical PMF of X.
5. (1 POINT) Compare the two PMFs.
6. (1 POINT) Compute for the statistical expectation of X and compare with the
theoretical expectation of X.
Part IV. Simulating a Poisson Random Variable
A Poisson random variable is a special case of the binomial random variable. In Poisson RV,
the probability of the number of successes in a fixed interval is analyzed. The Poisson
distribution is defined as:
𝑒 −𝜆 𝜆𝑘
𝑝𝑋 (𝑘) =
𝑘!
where λ is the average number of events per interval, e is the Euler’s number, and k is the
number of successful outcomes.
Exercise
Consider the stochastic experiment discussed in Problem 02 of DC 03. Let X be the number
of queries in an interval of one minute.
1. (2 POINTS) Simulate the random variable X for M = 1000. Use the function randp for
your simulation of a single Poisson experiment.
2. (1 POINT) Plot the statistical PMF of X. (Note: limit the values in your plot to the
maximum obtained in your simulation. You may use the function max).
3. (1 POINT) Plot the theoretical PMF of X.
4. (1 POINT) Compare the two PMFs.
5. (1 POINT) Compute for the statistical expectation of X and compare with the
theoretical expectation of X.