You are on page 1of 3

EEE 25: Probability and Statistics for Electrical Engineers 1

Module 01: Discrete Random Variables


Objectives:
- To simulate a stochastic experiment using Octave
- To visualize a random variable with the probability mass function
- To compare statistical experiments with probability theory.
Instructions:
- Save all files (scripts and documents) in one zip file named M1_Section_Surname.zip.
- Write your answers to each question on a separate document (.pdf).
- Tentative deadline of submission is on September 7, 2018 at 5:00PM
Part I. Introduction to Random Variables
Recall that a random variable is a function that associates a unique numerical value (i.e.
probability of an outcome) with every outcome of an experiment. A random variable can
either be discrete or continuous depending on the type of experiment. Examples of DRV
include rolling a dice, tossing a coin, drawing a card, or picking a marble from an urn. CRV,
on the other hand, includes parameters with continuous values such as the amount of
current through a resistor, the mass of an object, or the distance of an object from another.
A random variable is visualized by the probability distribution function and/or the
cumulative distribution function. In this module, we will explore these concepts using
Octave.
Part II. Simulating a Stochastic Experiment
Let us denote X to be the random variable of some stochastic experiment. We denote the
number of trials for this experiment as M. To simulate a discrete random variable, we use
the function rand, which generates a number at random within the [0, 1] interval (for more
information, type help rand in the command window). Assume that in general the possible
values of X are {x1, x2, …, xN} with probabilities {p1, p2, …, pN). The following code segment
simulates this stochastic experiment.
for i = 1:M
u = rand(1,1);
if u <= p1
x(i,1) = x1;
elseif u > p1 & u <= p1 + p2
x(i,1) = x2;
elseif u > p1 + p2 & u <= p1 + p2 + p3
x(i,1) = x3;

elseif u > p1 + p2 + … + pN-2 & u <= p1 + p2 + … + pN-1
x(i,1) = xN-1
elseif u > p1 + p2 + … + pN-1
x(i,1) = xN
end
end
Alvarez | Cajote | Ong | Tolentino | Vidal | EEE 25 AY1819S1
EEE 25: Probability and Statistics for Electrical Engineers 2

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.

Alvarez | Cajote | Ong | Tolentino | Vidal | EEE 25 AY1819S1


EEE 25: Probability and Statistics for Electrical Engineers 3

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.

Alvarez | Cajote | Ong | Tolentino | Vidal | EEE 25 AY1819S1

You might also like