0% found this document useful (0 votes)
34 views

Stochastic Systems: Assignment #03

1) The document describes two methods for generating random variables - the transformation method and the rejection method. 2) For the transformation method, Matlab code is provided to generate an exponential random variable with expected value 5 using inverse transform sampling. 3) For the rejection method, Matlab code generates an exponential random variable with expected value 5 using a bounding rectangle and only accepting values within it.

Uploaded by

Umair Zulfiqar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
34 views

Stochastic Systems: Assignment #03

1) The document describes two methods for generating random variables - the transformation method and the rejection method. 2) For the transformation method, Matlab code is provided to generate an exponential random variable with expected value 5 using inverse transform sampling. 3) For the rejection method, Matlab code generates an exponential random variable with expected value 5 using a bounding rectangle and only accepting values within it.

Uploaded by

Umair Zulfiqar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 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