Stochastic Systems Assignment: Table 3.1+3.2 Implementation On Matlab
Stochastic Systems Assignment: Table 3.1+3.2 Implementation On Matlab
Title of Assignment
Submitted to:
Sir Dr. Salman
Submitted by:
Syed Hassaan Ahmed Bukhari
Reg # 7339
Ms-83/Electrical(control) Engineering
Page 1
Question 1:
a.) Write Matlab code for PDF,CDF and PMF for Table 3.1
& 3,2?
Table 3.1:
p=0:1
p_0=1-p %pmf=p for sucees=0
p_1=p
%pmf=p for sucees=1
Mean=mean(p_1)
Var=var(p_1)
%in table
E=p
VAR=p.*(1-p)
plot(p,p_1)
Page 2
1
0.9
0.8
0.7
0.6
0.5
0.4
0.3
0.2
0.1
0
0.1
0.2
0.3
0.4
0.5
0.6
Page 3
0.7
0.8
0.9
0.2
0.18
0.16
0.14
0.12
0.1
0.08
0.06
0.04
0.02
0
10
15
hold on
stem(k,pmf)
hold off
end
MEAN=mean(pmf) % acc to Matlab command
VARiance=var(pmf) %acc to Matlab command
E=n*p %acc to table 3.1
Var=n*p*(1-p) %acc to table 3.1
Page 4
20
25
0.18
0.16
0.14
0.12
0.1
0.08
0.06
0.04
0.02
0
10
15
For CDF:
CDF=integration(PDF)
n=15;
p=0.5
%using Geometric R.V
n=15;
p=0.5
for k=1:n
pmf=(p)*((1-p)^(k-1) )
%P[M=k]=(1-p)^(k-1) *P
Page 5
20
25
hold on
stem(k,pmf)
hold off
end
MEAN=mean(pmf) % acc to Matlab command
VARiance=var(pmf) %acc to Matlab command
E=(1-p)/p %acc to table 3.1
Var=(1-p)/p^2 %acc to table 3.1
0.5
0.45
0.4
0.35
0.3
0.25
0.2
0.15
0.1
0.05
0
10
n=15;
p=0.3
%using Geometric R.V
n=15;
p=0.3
for k=1:n
pmf=(p)*((1-p)^(k-1) )
%P[M=k]=(1-p)^(k-1) *P
hold on
stem(k,pmf)
Page 6
15
hold off
end
MEAN=mean(pmf) % acc to Matlab command
VARiance=var(pmf) %acc to Matlab command
E=(1-p)/p %acc to table 3.1
Var=(1-p)/p^2 %acc to table 3.1
0.35
0.3
0.25
0.2
0.15
0.1
0.05
0
10
For CDF:
n=15;
p=0.3
for k=1:n
pmf=(p)*((1-p)^(k-1) ) %P[M=k]=(1-p)^(k-1) *P
T=@(k) pmf;
CDF=integral(T,1,15,'ArrayValued',true)
hold on
stem(k,cdf)
hold off
end
MEAN=mean(pmf) % acc to Matlab command
VARiance=var(pmf) %acc to Matlab command
E=(1-p)/p %acc to table 3.1
Var=(1-p)/p^2 %acc to table 3.1
Page 7
15
4.5
4
3.5
3
2.5
2
1.5
1
0.5
0
10
15
hold on
stem(k,pmf)
hold off
end
MEAN=mean(pmf) % acc to Matlab command
VARiance=var(pmf) %acc to Matlab command
E=r/p %acc to table 3.1
Var=(r*(1-p))/p^2 %acc to table 3.1
Page 8
0.5
0.45
0.4
0.35
0.3
0.25
0.2
0.15
0.1
0.05
0
10
11
For CDF:
%USING nEGATIVE bINOMIAL r.v
n=10;
r=1;
p=0.5
for k=r:r+n
pmf=((factorial(k-1))/((factorial(r-1))*(factorial(k-r))))*((p^r)*((1-p)^(kr)))
T=@(k) pmf;
CDF=integral(T,1,10,'ArrayValued',true)
hold on
stem(k,CDF)
hold off
end
MEAN=mean(pmf) % acc to Matlab command
VARiance=var(pmf) %acc to Matlab command
E=r/p %acc to table 3.1
Var=(r*(1-p))/p^2 %acc to table 3.1
Page 9
10
15
At alfa=n*p=24*0.5=12
Syed Hassaan Ahmed(7339)
Page 10
20
25
n=24;
p=0.5
e=2.713
alfa=n*p
for k=0:n
pmf=(alfa^k/factorial(k))*e^-alfa
hold on
stem(k,pmf)
hold off
end
MEAN=mean(pmf) % acc to Matlab command
VARiance=var(pmf) %acc to Matlab command
E=alfa %acc to table 3.1
Var=alfa %acc to table 3.1
0.12
0.1
0.08
0.06
0.04
0.02
10
15
FOR CDF:
At Alfa=0.75
n=24;
p=0.5
e=2.713
alfa=0.75
for k=0:n
Page 11
20
25
pmf=(alfa^k/factorial(k))*e^-alfa
T=@(k) pmf;
CDF=integral(T,1,24,'ArrayValued',true)
hold on
stem(k,CDF)
hold off
end
MEAN=mean(pmf) % acc to Matlab command
VARiance=var(pmf) %acc to Matlab command
E=alfa %acc to table 3.1
Var=alfa %acc to table 3.1
TABLE 3.2:
6) For Uniform Random Variable:
For PDF:
a=1
b=10
for x=a:b
cdf=(x-a)./(b-a) ;
pdf=polyder(cdf) %as pdf=differentiation(cdf)
hold on
subplot(2,1,1)
plot(x,cdf,'b')
subplot(2,1,2)
plot(x,pdf,'b')
hold off
end
MEAN=mean(cdf) % acc to Matlab command
VARiance=var(cdf) %acc to Matlab command
E=(a+b)/2 %acc to table 3.1
Var=(b-a)^2/12 %acc to table 3.1
Page 12
1
0.9
0.8
0.7
0.6
0.5
0.4
0.3
0.2
0.1
0
For CDF:
a=1
b=10
for x=a:b
cdf=(x-a)./(b-a) ;
pdf=polyder(cdf) %as pdf=differentiation(cdf)
T=@(x) pdf;
CDF=integral(T,1,10,'ArrayValued',true)
hold on
subplot(2,1,1)
plot(x,cdf,'b')
subplot(2,1,2)
plot(x,pdf,'b')
hold off
end
MEAN=mean(cdf) % acc to Matlab command
VARiance=var(cdf) %acc to Matlab command
E=(a+b)/2 %acc to table 3.1
Var=(b-a)^2/12 %acc to table 3.1
Page 13
10
0.7
0.6
0.5
0.4
0.3
0.2
0.1
0
10
15
Page 14
20
25
FOR CDF:
n=15
p=0.4
alfa=n*p
T=10
%T=time in seconds
lameda=alfa/T
for x=0:n
pdf=lameda*exp(-lameda.*x)
T=@(x) pdf;
CDF=integral(T,0,15,'ArrayValued',true)
hold on
plot(x,pdf)
hold off
end
MEAN=mean(pdf) % acc to Matlab command
VARiance=var(pdf) %acc to Matlab command
E=1/lameda %acc to table 3.1
Var=1/lameda^2 %acc to table 3.1
Page 15
hold on
plot(x,pdf)
hold off
end
MEAN=mean(pdf) % acc to Matlab command
VARiance=var(pdf) %acc to Matlab command
E=m %acc to table 3.1
Var=sigma.^2 %acc to table 3.1
For Sigma=0.4;0.5;0.6
1.6
1.4
1.2
1
0.8
0.6
0.4
0.2
0
FOR CDF:
%For Guassian Random Variable
sigma=0.5
m=5;
for x=0:10
pdf=(exp(-(x-m)^2)/(2*sigma^2))./((sqrt(2*pi))*sigma)
T=@(x) pdf;
CDF=integral(T,0,10,'ArrayValued',true)
hold on
plot(x,pdf)
Page 16
10
hold off
end
MEAN=mean(pdf) % acc to Matlab command
VARiance=var(pdf) %acc to Matlab command
E=m %acc to table 3.1
Var=sigma.^2 %acc to table 3.1
%T=gamma function
pdf=(lameda.*(lameda.*x).^(alfa-1)).*(exp(-lameda.*x))./T
hold on
plot(x,pdf)
hold off
end
MEAN=mean(pdf) % acc to Matlab command
VARiance=var(pdf) %acc to Matlab command
E=alfa/lameda %acc to table 3.1
Var=alfa/lameda.^2 %acc to table 3.1
Page 17
0.7
0.6
0.5
0.4
0.3
0.2
0.1
0
FOR CDF:
alfa=0.5
m=0;
lameda=1;
z=0.5;
for x=0:10
fun=@(x) x.^(z-1).*exp(-x);
T=integral(fun,0,10)
%T=gamma function
pdf=(lameda.*(lameda.*x).^(alfa-1)).*(exp(-lameda.*x))./T
T=@(x) pdf;
CDF=integral(T,0,10,'ArrayValued',true)
hold on
plot(x,pdf)
hold off
end
MEAN=mean(pdf) % acc to Matlab command
VARiance=var(pdf) %acc to Matlab command
E=alfa/lameda %acc to table 3.1
Var=alfa/lameda.^2 %acc to table 3.1
Page 18
10
For Alfa=1;0.7;0.5
0.7
0.6
0.5
0.4
0.3
0.2
0.1
0
Page 19
10
FOR CDF:
%For Guassian Random Variable
sigma=0.5
alfa=1;
for x=0:10
pdf=(x./alfa.^2).*(exp((-x^2)./(2*sigma.^2)))
T=@(x) pdf;
CDF=integral(T,0,10,'ArrayValued',true)
hold on
plot(x,pdf)
hold off
end
MEAN=mean(pdf) % acc to Matlab command
VARiance=var(pdf) %acc to Matlab command
E=alfa.*(sqrt(pi./2)) %acc to table 3.1
Var=(2-pi/2).*alfa.^2 %acc to table 3.1
Page 20
0.07
0.06
0.05
0.04
0.03
0.02
0.01
For CDF:
%For Cauchhy Random Variable
alfa=5;
for x=0:10
pdf=(alfa./pi)./((x.^2)+(alfa.^2))
T=@(x) pdf;
CDF=integral(T,0,10,'ArrayValued',true)
hold on
plot(x,pdf)
hold off
end
MEAN=mean(pdf) % acc to Matlab command
VARiance=var(pdf) %acc to Matlab command
Page 21
10
pdf=(alfa./2).*(exp(-alfa.*x))
hold on
plot(x,pdf)
hold off
end
MEAN=mean(pdf) % acc to Matlab command
VARiance=var(pdf) %acc to Matlab command
E=0 %acc to table 3.2
Var=2/alfa.^2 %acc to table 3.2
2.5
1.5
0.5
FOR CDF:
%For Cauchhy Random Variable
alfa=5;
for x=0:10
pdf=(alfa./2).*(exp(-alfa.*x))
T=@(x) pdf;
CDF=integral(T,0,10,'ArrayValued',true)
hold on
plot(x,pdf)
hold off
Page 22
10
end
MEAN=mean(pdf) % acc to Matlab command
VARiance=var(pdf) %acc to Matlab command
E=0 %acc to table 3.2
Var=2/alfa.^2 %acc to table 3.2
Page 23