Download as pdf or txt
Download as pdf or txt
You are on page 1of 11

Machine Problem 1

Aaron Jericho S. Mendoza#1, Jeremy Daniel G. Petilla#2, Cayl Cedric M. Ronquillo #3


3ECE-B, Group 2

Department of Electronics Engineering


Faculty of Engineering, University of Santo Tomas
España, Manila, Philippines
aaronjericho.mendoza.eng@ust.edu.ph 1, jeremydaniel.petilla.eng@ust.edu.ph 2,

caylcedric.ronquillo.eng@ust.edu.ph 3

Abstract— The purpose of this paper is to feature the subject profession as it enables them to understand random phenomena
matters in the course, MATH 301: Probability Theory and and effectively predict or control them despite the complexity
Random Processes namely, Probability Mass/Density of these situations.
Function, Cumulative Distribution Function, Laplace The union of these two has become the core for any scientific
Random Variable, and Gaussian Random Variable. A and engineering project. Without probability and statistics
machine problem was made with the aid of Matrix projects done will not be consistent and trustworthy opposite to
Laboratory to emphasize, visualize, and highlight the what it should be.
significance of the said course via a script and a function file This machine problem covers the probability mass/density
that yields the output required. function, cumulative distribution function, Laplace random
variable, and Gaussian random variable and the underlying
Index Terms—Probability Mass/Density Function, concepts behind it are the main content. Explanations and
Cumulative Distribution Function, Laplace Random concepts of the theories mentioned will be discussed in the
Variable, Gaussian Random Variable. latter part of the paper (II. Theory).
For this machine problem, a programming language,
MATLAB or Matrix Laboratory, is to be used. This
I. INTRODUCTION programming environment has functions and programs that
In the field of science and engineering, factors like quantities could help in creating and performing tasks such as computing,
and probabilities are very vital when it comes data gathering. A plotting graphical representations and several others concerning
data, may it be descriptive or quantitative, small-scale or large- functions. This programming environment aids the need for this
scale, are significant specifically in Electronics Engineering. machine problem which is composed of probability
Probability and Statistics are good examples that describe the mass/density function, cumulative distribution function,
Communications track. Laplace random variable, and Gaussian random variable.
In a wide context, Probability theory is basically the study of This machine problem requires knowledge and
random phenomena in which the result varies as it produces comprehension in relation with the topics mentioned earlier. It
outcomes that are formed by essential patterns behind. The aims to further develop the students’ analytical skills, critical
mathematics of probability is made to describe certain thinking and discernment when it comes to complex situations
situations wherein one can’t reproduce the product created by in these subject matters
just repeating the procedures done. Even with the same process
different trials yields to different results which causes the need II. THEORY
for a probability theory that copes up the irregularity of the Random Variable
outcome by observing the system behind. A random variable is a real-valued function which consists
Meanwhile, Statistics deals with the collection, processing, of an experiment with a probability measure defined on a sample
analysis, and interpretation of numerical data that comes crucial space S and assigns a real number to each outcome in the sample
in every aspect of engineering. Statistics plays a major role in space of the experiment. Random variables have two
all branches of engineering specifically electronics engineering classifications, discrete and continuous. It is called discrete
which can be more effective if research, development, and when its range is finite or countably infinite. It is continuous
production are aligned with a substantial data. These numerical when it can take an uncountable infinite number.
data provided by statistical approach are mainly the basis of the
movements to be selected for almost the entire process.
Statistics has become the support of engineers throughout their
Probability Mass Function Erlang Distribution
The Probability Mass Function (PMF) is a probability The Erlang distribution was initially developed by A.K. Erlang
measure that gives probabilities that a random variable can take. to examine the number of telephone calls which might be made
It is written as: at the same time. This distribution is the continuous distribution
of the sum of k independent and identically distributed random
variables each having an exponential distribution. Defined with
positive integers, its PDF is given by

𝑷𝑿 (𝒙) = 𝑷[𝑿 = 𝒙] 𝝀𝒌 𝒙𝒌−𝟏 𝒆−𝝀𝒙


𝒇𝑿 (𝒙) =
(𝒌 − 𝟏)!

Fig. 1 The standard notation for the PMF of X. [1]


for x, 𝝀 ≥ 𝟎
The PMF of a discrete random variable provides Fig. 4 The standard notation for Erlang PDF. [4]
probabilities for all possible values of x. This function can be
represented in a table, graph, or formula. where the parameter k is called the shape parameter, and the
parameter λ is called the rate parameter.
Binomial Distribution
In probability theory, the binomial distribution is used when a Probability Density Function
trial has exactly two mutually exclusive outcomes. These Probability density function (PDF) is a function in the
outcomes are usually considered “success” and “failure”. This probability theory whose integral is calculated to find
distribution is used to obtain the probability of observing x probabilities associated with a continuous random variable. It
successes in N trials while assumes that the probability of can be defined as:
success, denoted by p, on a single trial is fixed for all trials. The
formula for the binomial probability mass function is

𝒅𝑭𝑿 (𝒙)
𝒇𝑿 (𝒙) =
𝒅𝒙
𝒏
𝑷𝑿 (𝒙) = ( ) (𝒑)𝒙 (𝟏 − 𝒑)(𝒏−𝒙)
𝒙
Fig. 5 Definition of Probability Density Function. [5]

Mean and Variance


The expected value which is also referred to as the mean,
Fig. 2 The standard notation for binomial PMF. [2] consists of possible values of a random variable with weights
given by their respective theoretical probabilities. The formula
Pascal Distribution for mean can be acquired by multiplying each possible value
The Pascal Distribution, also known as the negative binomial for the random variable by the probability that the random
distribution relates to a random experiment with repeated variable takes and getting the summation of all these products.
independent trials observing m numbers of successes. The It can be written as
Pascal PMF is given by


𝑬(𝒙) = ∫ 𝒙𝒇(𝒙)𝐝𝐱
−∞

𝒏 − 𝟏 (𝒑)𝒙−𝟏
𝑷𝑿 (𝒙) = ( ) (𝟏 − 𝒑)(𝒏−𝒙) 𝑬(𝒙) = ∑ 𝒙𝒊 𝑷 (𝒙𝒊 )
𝒙−𝟏

Fig. 6 Formula for mean for continuous and discrete random


variables. [6]
Fig. 3 Pascal Probability Mass Function. [3]
The variance of a random variable can be defined as the III. PROBLEM 1
expected value of the square of the difference between the The first machine problem requires a function file that plots
random variable and the mean. Given that the random variable the probability mass/density function and the cumulative
X has a mean of µ, then the variance is expressed as: distribution function of the following random variables. It also
computes for the mean and variance of the random variables
used. The function name and the arguments used are shown in
the figure 1 is shown below:

𝑽𝒂𝒓(𝑿) = 𝑬[(𝑿 − 𝝁)𝟐 ]

Fig. 9 The required function name and the arguments used


Fig. 7 Variance of the Random Variable X. [6]
In this function file, the main focus of the problem is to plot
Laplace Distribution the probability mass/density function and the cumulative
The Laplace random variable, commonly known as distribution function. In order to provide a code that will satisfy
the Laplace distribution is one of the most known probability the required output using MATLAB, a switch-case statement is
distributions. This distribution is named after the French used. The switch-case statement evaluates an expression and
mathematician Pierre-Simon Laplace. Like the normal chooses to execute one of several groups of statements [ ]. For
distribution, this distribution is unimodal (with one peak) and loops in each distribution is also used for it is easy to create
symmetrical. However, the peak of the Laplace distribution is compared to other loops. The problem required three
sharper than the normal distribution. probability distribution options namely, Binomial, Pascal, and
Erlang. The parameter and range are based from these given
The Laplace distribution is the result of two probability distribution that the user wants to enter. First is the
exponential distributions, one positive and one negative. It is binomial distribution which has the following formula stated in
also called the double exponential distribution, because it looks Fig. 2.
like two exponential distributions spliced together back-to-
back. The Laplace distribution is expressed as: The Binomial (n, p) random variable’s “p” is always less
than 1 and greater than 0 where its n is always greater than or
equal to 1. To be able to construct this program, the students
used a switch function for each of the probability distribution
and after that an error detection was created using the if else
function to distinguish if the entered parameter is correct and
𝒂 −𝒂|𝒙−𝒃| for the case of binomial distribution, if the param(1) is equal to
𝒇𝑿 (𝒙) = 𝒆 range(2). If these conditions are not met, the program won’t
𝟐 start but if the conditions set are met, the program will now start
and read the formula for coded for mean, variance, probability
mass function and cumulative distribution function which is
computed only by summing up the PMF in each position. An
example of an argument including its mean, variance, and plot
Fig. 8 Probability density function of Laplace random variable. [7]
are shown in figures 3 and 4, respectively:
Central Limit Theorem
The central limit theorem in probability theory sates that,
given certain conditions, the arithmetic mean of a sufficiently
substantial number of iterates of independent random variables,
each with a well defined expected value and well-defined
variance, will be approximately normally distributed,
regardless of the underlying distribution.

Gaussian Distribution
The Gaussian distribution, commonly known as normal
distribution or the bell-shaped curve, is a continuous function
Fig. 10 Argument with Mean and Variance
in probability theory which approximates the exact binomial
distribution of events.
Fig. 11 Plot of the PMF and CDF of the Binomial distribution
Fig. 13 Plot of the PMF and CDF of the Pascal distribution
Second is the pascal distribution which has the formula
Third and last distribution is the Erlang which has the
mentioned in Fig. 5. The Pascal (k, p) random variable’s “p” is
following formula mentioned in Fig. 3. The Erlang (n, ƛ)
also less than 1 and greater than 0 where its “k” is always
random variable’s “p” is still less than 1 and greater than 0
greater than or equal to 1. A switch function was also used for
where its lambda is greater than 0 and its n is greater than or
this distribution and its error detection only covers incorrect
equal to 1. A switch function was also used for this distribution
parameter inputs unlike the binomial distribution which needs
and its error detection only covers incorrect parameter inputs
the param(1) and range(2) to be equal. If this condition is met
similar in Pascal distribution. If this condition is met by the user
by the user the program will now start and read the coded
the program will now start and read the coded formula for its
formula for Pascal’s PMF. Its CDF will also be read like how
PDF and CDF. An example of an argument including its mean,
the CDF of Binomial distribution works. An example of an
variance, and plot are shown in figures 9 and 10, respectively:
argument including its mean, variance, and plot are shown in
figures 6 and 7, respectively:

Fig. 14 Argument with Mean and Variance

Fig. 12 Argument with Mean and Variance

Fig. 15 Plot of the PMF and CDF of the Erlang distribution


IV. PROBLEM 2 V. PROBLEM 3
The second machine problem required a script file that plots The third problem requires to create a script file that
the probability density function (PDF) and cumulative produces 15 000 random samples of the given Central Limit
distribution function (CDF) of the Laplace (a, b) random Theorem equation, then find P[X<=x] of those samples. The
variable. This machine problem also estimates the mean and result is to be compared to the result of the Gaussian (0,1)
variance of 10,000 samples using the rand () function. random variable.

𝑎 −𝑎|𝑥−𝑏|
𝑓𝑋 (𝑥) = 𝑒
2 𝑋 =( ∑12
𝑖=1 𝑈𝑖 ) – 6

Fig. 16 The Laplace (a,b) random variable


Fig. 18 The Equation that is, according to the Central Limit Theorem, is
The first part of this machine problem asks to plot the PDF equivalent to the Gaussian (0,1) random variable.
and CDF of the Laplace random variable. To be able to do this,
the value for the sample space X was first initiated. The values There are 3 parts in this problem. First is to create a script
of X were taken from all positive integers from 0 to 4. This is file that generates 15 000 random samples of the random
because any value that far exceeds 4 will produce an inaccurate variable X. To do this, a for loop is required. The loop lets the
plot. The increment selected was 0.01 so that the plot will program continue to generate random variables from the
contain smoother slopes. Given array X and the values for a and equation in Fig. 4 until 15 000 samples are generated and stored
b which were 3 and 2 respectively, the formula for the Laplace in vector X.
PDF was used. To obtain its CDF, the integral function of
MATLAB was used, and a new array was created using a for The second part of the problem required to solve for
loop sequence. After the completing the syntax for both P[X<=x]. To do this, two for loops are needed. One is for the
functions, the plot below was obtained values of x (-4 to 4) and the other is for the 15000 samples. An
if-loop is used to compare x and the samples and check which
samples are less than x. The variable k is used as a counter to
how many samples are less than x. The results are stored in Y.
Z is used to store the values -4 to 4, with increment of 0.1.
The third part of the problem needs the use of the Gaussian
(0,1) random variable as X and compare it to the results of the
central limit equation.

Fig. 19 The formula of the CDF of the Gaussian (0,1) random variable

Fig. 17 Output plot for Machine Problem no. 2. To do this, the P[X=x] of the Central Limit Theorem
equation is needed, as well as the CDF and PDF of the Gaussian
The second part of the machine problem asks to generate 10,000 (0,1) random variable. P[X=x] is taken by using the histogram
samples using the rand( ) function and estimate its mean and command. The histogram command takes the vector X and gets
variance. To be able to execute the required task, the student the normalization pdf of the said vector. The CDF of the
created an algorithm that makes use of the rand( ) function to Gaussian (0,1) random variable is taken by using a for loop and
generate an array of 10,000 random numbers. After creating the using the equation of the CDF of the Gaussian (0,1) random
array, the min and max values were obtained using the variable seen in Figure 5.
respective MATLAB functions min( ) and max( ). These values
are to be the limits to obtain the mean and the variance. The
mean is then calculated by using the formula for continuous
random variables as mentioned in Fig. 5. Then after getting the
mean, the variance was also acquired by using the formula
mentioned in Fig. 6.
Fig. 20 The formula of the PMF of the Gaussian (0,1) random variable
The PMF of the Gaussian (0,1) random variable is taken by VII. REFERENCES
using the equation of the PDF of the Gaussian Random Variable [1] Hossein Pishro-Nik. Probability Mass Function [Online]. Available:
found in Figure 6. All these four results are plotted by subplot https://www.probabilitycourse.com/chapter3/3_1_3_pmf.php
for comparison. [2] Nist Sematech. Binomial Distribution [Online]. Available:
https://www.itl.nist.gov/div898/handbook/eda/section3/eda366i.htm
[3] Hossein Pishro-Nik. Special Distributions [Online]. Available:
https://www.probabilitycourse.com/chapter3/3_1_5_special_discrete_distr.php

[4] Erlang Distributions [Online]. Available:


https://ipfs.io/ipfs/QmXoypizjW3WknFiJnKLwHCnL72vedxjQkDDP1
mXWo6uco/wiki/Erlang_distribution.html

[5] Prababiliy DencityFunctions [Online]. Available:


http://mathworld.wolfram.com/ProbabilityDensityFunction.html

[6] Random Variables: Mean, Variance, and Standard Deviation [Online].


Available: https://www.mathsisfun.com/data/random-variables-mean-
variance.html

[7] Springer. Laplace Distribution [Online]. Available:


https://www.encyclopediaofmath.org/index.php/Laplace_distribution

Fig. 21 The graphs of the Central Limit Theorem equation and the
Gaussian (0,1) random variable equation
VIII. DISTRIBUTION OF TASK
VI. CONCLUSION 1. Mendoza – Coding and Documentation for Problem 2,
The focus of this machine problem is to improve the Theory, References
students’ analytical skills relating MATH 301: Probability 2. Ronquillo – Coding and Documentation for Problem 1,
Theory and Random Processes to technical computing. Matrix Abstract, Introduction
Laboratory serves as a prototype of the students’ vision and 3. Petilla – Coding and Documentation for Problem 3,
understanding regarding the course. Obviously, it would help the Conclusion
students’ critical thinking especially in this subject matter but
what’s behind that is that through this machine problem,
students will be more likely to be creative and resourceful. This
means that through this machine problem, students’ are trained
for the outside world specifically having a job. When the time
comes one has a job, resources will not always be readily
available. There will always be something that’s missing, that’s
the job of engineers, to create something out of nothing. Relating
that to this machine problem is that in this paper, students are
required to follow the prescribed format set by the professor. An
Engineer can’t construct or good to say that should not construct
a gadget, building or other significant things in the society
without a neat plan. Residing to a concrete plan is a must when
it comes to safety. With the aid of this computing environment,
students will be able to think and widen their perspective when
it comes to coding. Further analyzation will be implemented for
the program to work. This relation of Math 301 with Matrix
Laboratory will truly show how a Thomasian Electronics
Engineering student analyzes situations deeply.
Each of the three given problems has their own uniqueness to
further improve critical thinking and comprehension.
Documenting the machine problems serves as a guide and
background to the readers. The students explained the topics
well by basing it to the theories and facts. All outputs required
are obtained and the students have improved their writing skills
by cautiously following the prescribed format.
Appendix
Problem 1: Create a function file that plots the probability mass/density function and the cumulative
distribution function of the following random variables.

function [ mean, var ] = pmf_cdf_plot( dist, param, range )


% a function file that will plot the probability mass/density function and
% cumulative distribution function of a random variable.
%PROGRAM BY: MENDOZA, PETILLA, RONQUILLO
% 3ECE-B GROUP 2

switch dist %Probability distribution to be used


case 'binomial' %binomial probability distribution
X = (range(2));
%Error Check if integer is equal to final range
if (param(1) ~= range(2))
disp('ERROR: unequal parameter and range')
%Error Check to see if parameter is between 0 and 1
elseif (param(2)<0 && param(2)>1)
disp('ERROR: incorrect parameter')
else
for j=range(1):1:range(2)
%Computation for PMF
X(j+1) = (factorial(param(1))/(factorial(j)*factorial(param(1)-
j)))*((param(2))^j)*(1-param(2))^(param(1)-j);
%Computation for CDF
if(j+1 == 1)
Y(j+1)=X(j+1);
else
Y(j+1)=X(j+1)+Y(j);
end
end
%Computation for Mean and Variance
mean = param(1)*param(2);
var = param(1)*param(2)*(1-param(2));
end
%Setting up plots for graph of PMF
subplot(1,2,1)
bar(range(1):range(2),X);
grid on
title('PMF')
xlabel('x')
ylabel('PDF')
%Setting up plots for graph of CDF
subplot(1,2,2)
stairs(range(1):range(2),Y);
grid on
title('CDF')
xlabel('x')
ylabel('PDF')
case 'Pascal' %Pascal probability distribution
X = (range(2));
%Error Check to see if parameter is between 0 and 1
if (param(2)<0 && param(2)>1)
disp('ERROR: incorrect parameter')
else
for j=range(1):1:range(2)
%Computation for PMF
if (j<param(1))
X(j+1)=0;
Y(j+1)=0;
else
X(j+1) = (factorial(j-1)/(factorial(param(1)-1)*factorial((j-1)-(param(1)-
1))))*((param(2))^param(1))*((1-param(2))^(j-param(1)));
%Computation for CDF
if(j == param(1))
Y(j+1)=X(j+1);
else
Y(j+1)=X(j+1)+Y(j);
end
end
end
%Computation for Mean and Variance
mean = param(1)/param(2);
var = (param(1)*(1-param(2)))/(param(2)^2);
end
%Setting up plots for graph of PMF
subplot(1,2,1)
bar(range(1):range(2),X);
grid on
title('PMF')
xlabel('x')
ylabel('PDF')
%Setting up plots for graph of CDF
subplot(1,2,2)
stairs(range(1):range(2),Y);
grid on
title('CDF')
xlabel('x')
ylabel('PDF')
case 'Erlang' %Erlang probability distribution
X = (range(2));
k=1;
%Computation for PMF
for j=range(1):1:range(2)
X(j+1) = (((param(2))^param(1))*(j^(param(1)-1))*exp(-
(param(2)*j)))/factorial(param(1)-1);
T=0;
%Computation for CDF
for i=0:1:param(1)-1
T=T+((1/factorial(i)))*(exp(-param(2)*j))*((param(2)*(j)^i));
end
Y(k)=1-T;
Z(k)=j;
k=k+1;
%Computation for Mean and Variance
mean = param(1)/param(2);
var = param(1)/(param(2)^2);
end
subplot(1,2,1)
bar(range(1):range(2),X);
grid on
title('PMF')
xlabel('x')
ylabel('PDF')
%Setting up plots for graph of PMF
subplot(1,2,2)
plot(range(1):range(2),Y);
grid on
title('CDF')
xlabel('x')
ylabel('PDF')
%Setting up plots for graph of CDF
otherwise
disp('ERROR: INCORRECT PROBABILITY DISTRIBUTION');

end

end

Problem 2: Create a script file that plots the probability density function and the cumulative distribution function
of a Laplace (𝒂 = 𝟑,𝒃 = 𝟐) random variable. Using 10,000 samples from rand(), estimate its mean and variance.

%Laplace(3,2)
clc;
clear;

x=10;
y=x;
a=3;
b=2;
z=0;
m=0;
for x=-x:0.01:y
z=z+1;
L(z)=(a/2)*exp(-a*abs(x-b));
end

x=y;
z=0;

for x=-x:0.01:y
z=z+1;
F(z)=integral(@(x) (a/2)*exp(-a*abs(x-b)) ,-Inf,x);
end

subplot(1,2,1)
plot(-y:0.01:y,L,'linewidth',2)
grid on
subplot(1,2,2)
plot(-y:0.01:y,F,'linewidth',2)
grid on

xrand=rand(10000,1);
xmin=min(xrand)*10000;
xmax=max(xrand)*10000;
x=xmin:0.0001:xmax;

expectation=integral(@(x) x.*(a/2).*exp(-a.*abs(x-b)) ,xmin,xmax)


variance=integral(@(x) x.^2.*(a/2).*exp(-a.*abs(x-b)) ,xmin,xmax)-expectation

Problem 3: a. Create a script file that generates 15,000 samples of the random variable 𝑋.
b. Based from the samples, solve for 𝑃[𝑋 ≤ 𝑥] for 𝑥 = −4,−3,…,3,4.
c. Repeat the previous problem when 𝑋 is a Gaussian (0, 1) random variable and compare the results

clc
clear
%Setting up 15 000 samples of random variable X
for j=1:1:15000
Ui = rand(1,12);
X(j) = sum(Ui) - 6;
end
%Computations for CDF of Central Limit Theorem
h=1;
for j=-4:0.1:4
k=0;
for l=1:1:15000
if (X(l) <= j)
k=k+1;
end
end
Y(h)=k;
Z(h)=j;
h=h+1;
end

for i=1:1:81
if Y(i) > 0
P(i) = Y(i)/15000;
else
P(i) = 0;
end
end
%Plotting CDF of Central Limit Theorem
subplot(2,2,1)
plot(Z,P)
title('Central Limit Theorem')
xlabel('x')
ylabel('P[X<=x]')

%Computation and Plotting of PMF of Central Limit Theorem


subplot(2,2,2)
histogram(X,'Normalization','pdf')
title('Central Limit Theorem')
xlabel('x')
ylabel('P[X=x]')

%Computation for CDF of Gaussian (0,1) Random Variable


%P[X<=x]
q=1;
for j=-4:0.1:4
CDF(q)=(1/2)*(1+erf((j-0)/(1*sqrt(2))));
q=q+1;
end
%Plotting for CDF of Gaussian (0,1) Random Variable
subplot(2,2,3)
line(Z,CDF)
title('Gaussian CDF')
xlabel('x')
ylabel('PDF')

%Computation and Plotting for PMF of Gaussian


%P[X=x]
subplot(2,2,4)
bar(Z,(exp(-(Z.^2)/2)/sqrt(2*pi)))
title('Gaussian PMF')
xlabel('x')
ylabel('PDF')

You might also like