Top Banner
Stochastic assignment Stochastic Systems Assignment Title of Assignment Table 3.1+3.2 implementation on Matlab Submitted to: Sir Dr. Salman Submitted by: Sikandar Javed Reg # 7326 Ms-83/Electrical(control) Engineering Page 1
24

Sikander

Feb 01, 2016

Download

Documents

Kashif Abbas

jj
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Sikander

Stochastic Systems Assignment

Title of Assignment

Table 3.1+3.2 implementation on Matlab

Submitted to:

Sir Dr. Salman

Submitted by:

Sikandar Javed

Reg # 7326

Ms-83/Electrical(control) Engineering

College of Engineering & Mechanical Engineering, NUST

Page 1

Page 2: Sikander

Bernoulli Random Variable:

p=0:1p_0=1-p %pmf=p for sucees=0p_1=p %pmf=p for sucees=1Mean=mean(p_1)Var=var(p_1)%in tableE=pVAR=p.*(1-p)plot(p,p_1)

Page 2

Page 3: Sikander

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 10

0.1

0.2

0.3

0.4

0.5

0.6

0.7

0.8

0.9

1

Binomial (pmf)N=50P=0.1

% binomial random variable %clcclear alln=50; % number of trialsp=0.1 %probability of successfor k=0:n % probability mass function pmf=((factorial(n))/((factorial(k))*(factorial(n-k))))*(p^k)*((1-p)^(n-k) ) hold on stem(k,pmf)end%according to table 3.1MEAN=mean(pmf) VARiance=var(pmf) E=n*p %farmulaVar=n*p*(1-p)%farmula

Page 3

Page 4: Sikander

0 5 10 15 20 25 30 35 40 45 500

0.02

0.04

0.06

0.08

0.1

0.12

0.14

0.16

0.18

0.2

Binomial (pmf)N=50P=0.5% binomial random variable %clcclear alln=50; % number of trialsp=0.5 %probability of successfor k=0:n % probability mass function pmf=((factorial(n))/((factorial(k))*(factorial(n-k))))*(p^k)*((1-p)^(n-k) ) hold on stem(k,pmf)end%according to table 3.1MEAN=mean(pmf) VARiance=var(pmf) E=n*p %farmulaVar=n*p*(1-p)%farmula

Page 4

Page 5: Sikander

0 5 10 15 20 25 30 35 40 45 500

0.02

0.04

0.06

0.08

0.1

0.12

Geometric random variable(pmf)

n=10;p=0.2for k=1:n pmf=(p)*((1-p)^(k-1) ) %P[M=k]=(1-p)^(k-1) *P hold on stem(k,pmf)end

Page 5

Page 6: Sikander

%according to table 3.1MEAN=mean(pmf) VARiance=var(pmf) E=(1-p)/p % expected value farmulaVar=(1-p)/p^2 % variance value farmula

1 2 3 4 5 6 7 8 9 100

0.02

0.04

0.06

0.08

0.1

0.12

0.14

0.16

0.18

0.2

%

For CDF:

n=15;p=0.3for 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 offendMEAN=mean(pmf) VARiance=var(pmf) E=(1-p)/p Var=(1-p)/p^2

Page 6

Page 7: Sikander

0 5 10 150

0.5

1

1.5

2

2.5

3

3.5

4

4.5

Negative random variable(pmf)

nagitive binomial random variable

n=20;r=2;p=0.5for k=r:r+npmf=((factorial(k-1))/((factorial(r-1))*(factorial(k-r))))*((p^r)*((1-p)^(k-r))) hold on stem(k,pmf)end%according to table 3.1MEAN=mean(pmf)

Page 7

Page 8: Sikander

VARiance=var(pmf) E=r/p %farmulaVar=(r*(1-p))/p^2 %farmula

2 4 6 8 10 12 14 16 18 20 220

0.05

0.1

0.15

0.2

0.25

For CDF:

%USING nEGATIVE bINOMIAL r.vn=10;r=1;p=0.5for k=r:r+npmf=((factorial(k-1))/((factorial(r-1))*(factorial(k-r))))*((p^r)*((1-p)^(k-r)))T=@(k) pmf; CDF=integral(T,1,10,'ArrayValued',true)

hold on stem(k,CDF) hold offendMEAN=mean(pmf) % according to commandVARiance=var(pmf) %acc to Matlab command E=r/p Var=(r*(1-p))/p^2

Page 8

Page 9: Sikander

Poisson random variable(pmf)n=20;p=0.3e=2.713alfa=0.8for k=0:n pmf=(alfa^k/factorial(k))*e^-alfa hold on stem(k,pmf) hold offend% according to table 3.1MEAN=mean(pmf) VARiance=var(pmf) E=alfa %farmulaVar=alfa %farmula

0 2 4 6 8 10 12 14 16 18 200

0.05

0.1

0.15

0.2

0.25

0.3

0.35

0.4

0.45

0.5

FOR CDF:

At Alfa=0.75

n=24;

Page 9

Page 10: Sikander

p=0.5e=2.713alfa=0.75for k=0:n pmf=(alfa^k/factorial(k))*e^-alfa T=@(k) pmf; CDF=integral(T,1,24,'ArrayValued',true)

hold on stem(k,CDF) hold offendMEAN=mean(pmf) % according to commandVARiance=var(pmf) %acc to Matlab command E=alfa Var=alfa

Uniform random variable

a=1b=10 for x=a:b cdf=(x-a)./(b-a) ; pdf=polyder(cdf) hold on plot(x,cdf,'b')end%according to table 3.2MEAN=mean(cdf) VARiance=var(cdf) E=(a+b)/2 Var=(b-a)^2/12

Page 10

Page 11: Sikander

1 2 3 4 5 6 7 8 9 100

0.1

0.2

0.3

0.4

0.5

0.6

0.7

0.8

0.9

1

For CDF:

a=1b=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 offendMEAN=mean(cdf) % according to command

Page 11

Page 12: Sikander

VARiance=var(cdf) %acc to Matlab command E=(a+b)/2Var=(b-a)^2/12

7) For Exponential Random Variable:

n=15p=0.4alfa=n*pT=10 %T=time in secondslameda=alfa/Tfor x=0:n pdf=lameda*exp(-lameda.*x) hold on plot(x,pdf)endMEAN=mean(pdf) % according to commandVARiance=var(pdf) %acc to Matlab command E=1/lameda %farmulaVar=1/lameda^2 %farmula

0 5 10 15 20 250

0.1

0.2

0.3

0.4

0.5

0.6

0.7

FOR CDF:

n=15p=0.4alfa=n*p

Page 12

Page 13: Sikander

T=10 %T=time in secondslameda=alfa/Tfor x=0:n pdf=lameda*exp(-lameda.*x) T=@(x) pdf; CDF=integral(T,0,15,'ArrayValued',true)

hold on plot(x,pdf) hold offendMEAN=mean(pdf) % according to commandVARiance=var(pdf) %acc to Matlab command E=1/lamedaVar=1/lameda^2

For Guassian Random Variable

sigma=0.5m=5;for x=0:10 pdf=(exp(-(x-m)^2)/(2*sigma^2))./((sqrt(2*pi))*sigma) hold on plot(x,pdf) % according to table 3.1MEAN=mean(pdf) VARiance=var(pdf) E=m Var=sigma.^2

For Sigma=0.4;0.5;0.6

Page 13

Page 14: Sikander

0 1 2 3 4 5 6 7 8 9 100

0.2

0.4

0.6

0.8

1

1.2

1.4

1.6

FOR CDF:

%For Guassian Random Variablesigma=0.5m=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) hold offendMEAN=mean(pdf) % according to commandVARiance=var(pdf) %acc to Matlab command E=mVar=sigma.^2

9. For Gamma Random Variable:

Page 14

Page 15: Sikander

FOR PDF:

alfa=0.5m=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 hold on plot(x,pdf) hold offendMEAN=mean(pdf) % according to commandVARiance=var(pdf) %acc to Matlab command E=alfa/lamedaVar=alfa/lameda.^2

For Alfa=0.5;1;2 and Lameda=1:

0 1 2 3 4 5 6 7 8 9 100

0.1

0.2

0.3

0.4

0.5

0.6

0.7

FOR CDF:

Page 15

Page 16: Sikander

alfa=0.5m=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))./TT=@(x) pdf;CDF=integral(T,0,10,'ArrayValued',true)

hold on plot(x,pdf) hold offendMEAN=mean(pdf) % according to commandVARiance=var(pdf) %acc to Matlab command E=alfa/lamedaVar=alfa/lameda.^2

10. For Rayleigh Random Variable:

FOR PDF:%For Guassian Random Variablesigma=0.5alfa=1;for x=0:10 pdf=(x./alfa.^2).*(exp((-x^2)./(2*sigma.^2))) hold on plot(x,pdf) hold offendMEAN=mean(pdf) % according to commandVARiance=var(pdf) %acc to Matlab command E=alfa.*(sqrt(pi./2))Var=(2-pi/2).*alfa.^2

For Alfa=1;0.7;0.5

Page 16

Page 17: Sikander

0 1 2 3 4 5 6 7 8 9 100

0.1

0.2

0.3

0.4

0.5

0.6

0.7

FOR CDF:

%For Guassian Random Variablesigma=0.5alfa=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 offendMEAN=mean(pdf) % according to commandVARiance=var(pdf) %acc to Matlab command E=alfa.*(sqrt(pi./2))Var=(2-pi/2).*alfa.^2

Page 17

Page 18: Sikander

11. For Cauchy Random Variable:

For PDF:

%For Cauchhy Random Variablealfa=5;for x=0:10 pdf=(alfa./pi)./((x.^2)+(alfa.^2)) hold on plot(x,pdf) hold offendMEAN=mean(pdf) % according to commandVARiance=var(pdf) %acc to Matlab command

0 1 2 3 4 5 6 7 8 9 100.01

0.02

0.03

0.04

0.05

0.06

0.07

For CDF:

%For Cauchhy Random Variable

Page 18

Page 19: Sikander

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 offendMEAN=mean(pdf) % according to commandVARiance=var(pdf) %acc to Matlab command

12.For Laplacian Random Variable:

FOR PDF:

%For Cauchhy Random Variablealfa=5;for x=0:10 pdf=(alfa./2).*(exp(-alfa.*x)) hold on plot(x,pdf) hold offendMEAN=mean(pdf) % according to commandVARiance=var(pdf) %acc to Matlab commandE=0 %acc to table 3.2Var=2/alfa.^2 %acc to table 3.2

Page 19

Page 20: Sikander

0 1 2 3 4 5 6 7 8 9 100

0.5

1

1.5

2

2.5

FOR CDF:

%For Cauchhy Random Variablealfa=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 offendMEAN=mean(pdf) % according to commandVARiance=var(pdf) %acc to Matlab commandE=0 %acc to table 3.2Var=2/alfa.^2 %acc to table 3.2

Page 20