You are on page 1of 3

close all; clear; clc;

%In modeling and simulation one often has a PDF f(x) and
corresponding CDF
%F(x) from which one would like to make random draws.
%
% Show that if one draws uniformly y~U(0,1) from F(x), then
one has
% x = F^-1(y) which is a random draw from f(x). The
Derivation is simple
% and you can look to the internet for a solution. As an
example, consider
% the exponential density f(x) = lambda* exp (-lambda*X). It
has a density
% that for lambda = 5 looks like:

N = 1000;
lambda = 5;
pdx = makedist('Exponential','mu',lambda)

steps = 0.01;
xval = 0:steps:15; %uniform distribution over
[0,1]

pdfX = pdf(pdx,xval);
cdfX = cdf(pdx,xval);

%Below shows the pdf and cdf of the exponential as shown in


the graphs in
%the HW. In addition was not able to figure out what the HW
meant about
%getting a random drawn out. Will have to look at the
results after turning
%in the HW.
plot(xval, pdfX);
title('P.D.F for Exponentioal R.V with Mean 5 (1/0.2)');
xlabel('X');
ylabel('Density f(x)');
xlim([0 18])
figure
plot(xval, cdfX);
title('C.D.F for Exponentioal R.V with Mean 5 (1/0.2)');
xlabel('X');
ylabel('Distribution F(x)');
xlim([0 18])
P.D.F for Exponentioal R.V with Mean 5 (1/0.2)
0.2

0.18

0.16

0.14

0.12
Density f(x)

0.1

0.08

0.06

0.04

0.02

0
0 2 4 6 8 10 12 14 16 18
X

C.D.F for Exponentioal R.V with Mean 5 (1/0.2)


1

0.9

0.8

0.7
Distribution F(x)

0.6

0.5

0.4

0.3

0.2

0.1

0
0 2 4 6 8 10 12 14 16 18
X
%Draw 1000 sample from a uniform distribution over [0,1].
Use these to
%preform random draws from the exponential distibution
above. Plot a
%histogram of these 1000 draws using the MATLAB "hist.m"
function. ALso
%plot the original random draws, e.g.plot(x)
y = rand(N,1);
pdy = makedist('Uniform');
F_1U = -lambda*log(1-pdy)
pdfy = pdf(pdy,y)
figure
histogram(pdfy,'Normalization','probability')

%This part I was not able to figure out might have been
overthinking this
%part this the best I could.

P.D.F for Uniform [0 1]


1

0.9

0.8

0.7
Density y~U(0,1)

0.6

0.5

0.4

0.3

0.2

0.1

0
0.5 0.6 0.7 0.8 0.9 1 1.1 1.2 1.3 1.4 1.5
X

You might also like