Page 103 - Computational Statistics Handbook with MATLAB
P. 103

90                         Computational Statistics Handbook with MATLAB


                                                 Fx() =  1 –  e – λx ;  0 < x <  ∞  .       (4.9)

                             Letting


                                                     u =  F x() =  1 –  e  – λx  ,         (4.10)

                             we can solve for x, as follows


                                                       u =  1 –  e – λx
                                                      e  – λx  =  1 –  u
                                                     – λx =  log ( 1 –  u)
                                                             1
                                                                    u
                                                       x =  – ---log ( 1 – ).
                                                             λ
                              By making note of the fact that 1 –  u   is also uniformly distributed over the
                             interval (0,1), we can generate exponential random variables with parameter
                             λ   using the transformation


                                                             1
                                                       X =  – ---log ()  .                 (4.11)
                                                                  U
                                                             λ
                             Example 4.6
                             The following MATLAB code will generate exponential random variables for
                                    λ
                             a given  .
                                % Set up the parameters.
                                lam = 2;
                                n = 1000;
                                % Generate the random variables.
                                uni = rand(1,n);
                                X = -log(uni)/lam;
                             We can generate a set of random variables and plot them to verify that the
                             function does yield exponentially distributed random variables. We plot a
                             histogram of the results along with the theoretical probability density func-
                             tion in Figure 4.4. The MATLAB code given below shows how we did this.

                                % Get the values to draw the theoretical curve.
                                x = 0:.1:5;
                                % This is a function in the Statistics Toolbox.
                                y = exppdf(x,1/2);
                                % Get the information for the histogram.
                                [N,h] = hist(X,10);
                                % Change bar heights to make it correspond to

                            © 2002 by Chapman & Hall/CRC
   98   99   100   101   102   103   104   105   106   107   108