Stochastic Systems: Assignment #03

You might also like

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

STOCHASTIC SYSTEMS

ASSIGNMENT #03

Submitted By:
NS Umair Zulfiqar
6629

Submitted To:
Sir Dr. M. Salman

College of Electrical and Mechanical Engineering


NUST

The Transformation Method:


Matlab Code:
clear all;
clc;
U=rand(1,100000);
% Array of uniform random numbers in the range[0,1]
y=5;
%Expected value
for i=1:100000
X(i)=-(log(U(i)))/y;
%Putting U in inverse function of exponential Random %Varaibles
end
Expected_value=1/mean(X)
%Expected value comes out to be equal to y
hist(X)
%Histogram of random variable generated
Variance=var(X)
%Variance of random variable generated

Figure:
Histogram:
4

x 10

0.5

1.5

Expected_value =
5.0135
Variance =
0.0400
The Rejection Method:
Matlab Code:
clc;
close all;
clear all;
x1=rand(1,10000);

%Array of Random numbers in the rage of [0,1]

2.5

t=5;
%Expected value
xx1=-t*x1;
%process of converting into exponential random variable
f=t*(exp(xx1))
%process of converting into exponential random variable
k=2;
b=k*f;
%Finding B for limit of Y
y=(b).*(rand(1,10000)) %Array of Random numbers in the rage of [0,b]
for i=1:10000
if y(i)<=f(i)
z(i)=y(i);
%If y<=f then put y in z
end
end
c = z(z ~= 0);
%All zero values are discarded
hist(c)
%Histogram of random variable generated
size(c)
%Size of the random variable as some of the zero values are %discarded

Figure:
Histogram:

4000
3500
3000
2500
2000
1500
1000
500
0

Size=
1

4995

0.5

1.5

2.5

3.5

4.5

You might also like