Professional Documents
Culture Documents
Stochastic Systems: Assignment #03
Stochastic Systems: Assignment #03
Stochastic Systems: Assignment #03
ASSIGNMENT #03
Submitted By:
NS Umair Zulfiqar
6629
Submitted To:
Sir Dr. M. Salman
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);
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