Vous êtes sur la page 1sur 1

COMPUTER PROBLEMS

GGeneration of Random Variables


The objective of this problem is to generate a random variable X that has a
linear probability density function as shown in Figure CP-5.1 (a); that is,

£ 0<x<2
Ix(x)= 2 - -:- .
{ o otherwise

The corresponding probability distribution function is

x < 0
{O
Fx(x) = P(X s x) = Lx> fx(v)dv = ;;
x
o ::: x ::: 2.
x>2

Fx(x) is shown in Figure CP-5.1(b). Note that 0 ::: Fx(x) ::: 1.

~._--

l...------~ f(x) F(x)


- -,~

1 1

Figure CP-5.1 (a) A


linear probability density
function and (b) the .
o 2 x o 2 x corresponding probability
(a) (b) distribution function.

To generate a sequence of samples of the random variable X, say {Xi}, we use


MATLAB to generate uniformly distributed random variables {Ui} in the range
(0, 1). Then, we set

x2
F(xj) = _I = u,
4
and solve for x., Thus, Xi = 2.,fiii. Clearly, the range of Xi is (0,2).

1. Generate 10,000 samples of the random variable X by using the procedure


previously described.
2. By subdividing the interval (0, 2) into 20 equally spaced subintervals
(bins), count the number of samples {Xi} that fall into each bin and plot
a histogram of the 10,000 randomly generated samples. Compare the
histogram with the linear probability density function [x (x) and comment
\
on how well the histogram matches Ix(x).

..
I

Vous aimerez peut-être aussi