316, exercise 1: Develop a random-variate generator for a random variable X with the
p.d.f.:
e 2x < x 0
f ( x ) = 2 x
e 0< x <
x 1
e2 x x0
F ( x) =
f ( y )dy = 2
1 12 e 2 x x>0
1
2
e2 X = R 0 R 12
1 12 e2 X = R 12 < R 1
X = 12 ln(2 R) 0 R 12
X = 12 ln(2(1 R)) 12 < R 1
N := 100000
R := runif ( N , 0 , 1)
i := 0 .. N 1
X := if R > .5 , .5 ln 2 1 R
i i ( ) , .5 ln(2 Ri)
i
M := 1000
k := 0 .. M 1
histogram( M , X)
h :=
N
0.015
0.01
hk, 1
0.005
0
5 .10 5 .10 1 .10
5 5 4
0
hk, 0
2. p. 316, exercise 4: Develop a generator for a triangular distribution with range (1,10) and
mean of 4.
2( x a)
( b a)( c a) , a x b
2( c x)
f (x ) = , b <x c
( c b )( c a)
0, otherwise
a +b +c
E( X ) =
3
2(10 x )
, 1 < x 10
f ( x ) = 81
0, otherwise
0, x a
( x a) 2
, a <x b
(b a )( c a )
F ( x) =
1 ( c x)
2
, b <x c
( c b )( c a)
1, x>c
0, x 1
(10 x ) 2
F ( x) = 1 , 1 < x 10
81
1, x > 10
(10 X ) 2
R = 1
81
81R = 81 (10 X )2
81 81R = (10 X )2
9 1 R = 10 X
X = 10 9 1 R
X = 10 9 R
2
3. p. 316, exercise 7: Given the p.d.f. f(x) = x /9 on 0 <= x <= 3, develop a generator for this
distribution.
x2
0 x3
f (x) = 9
0
otherwise
x 1
x3 0 x3
F ( x) = f ( y) dy = 27
Note: the integral is x3/9, but F(x) has
0 otherwise
to be adjusted by a constant to have a
maximum value of 1
1
27 X3 = R
X = 3 27 R