Prelab Exercise 1
(4)
To generate random number with uniform distribution The probability density function of a uniformly distributed random variable X defined in [a,b] is shown below
Some useful Matlab commands are listed below
fx(x)
1
rand-to generate uniform distributed random variableX
pdf-to obtain the probability density function(pdf cdf-to obtain the cumulative distribution function(cdf hist -- to plot the histogram of sample data
a
To generate sample values with uniform distribution in the range of a= -3 and b=7
% uniformly distributed random number a=-3;b=7; % range of x [-3 7] x=a+b-a*rand1,1e4; % x with uniform distribution pdfy=pdf'unif',x,a,b); % pdf cdfz=cdf'unif',x,a,b); % cdf
figure(l); subplot3ll);hist(x,a:0.2:b);ylabel('Occurrence'); axis[a-1 b+1 0 300]; grid; subplot(3l2); plot(x,pdfy); ylabel('pdf of X'); axis([a-l b+l 0 0.2]); grid; subplot(3l3); plot(x,cdfz); ylabel('cdf of X'); axis([a-l b+1 0 l.2]); grid; xlabel('variable x');
(a) (2) Use the histogram (311) to estimate the pdf.
Occurrence for each container (approx.) =
Probability for each container (approx.) =
Width of each container =
= ypd
(b) (2) Write down the mathematical expression of the cdf.
1