Page 102 - Computational Statistics Handbook with MATLAB
P. 102

Chapter 4: Generating Random Variables                           89

                                1. Generate a variate Y from the discrete uniform density on 1 … 5,  ,  .
                                   (One could use the MATLAB Statistics Toolbox function unidrnd
                                   or csdunrnd.)
                                2. Generate a uniform random number U.
                                3. If

                                                      p       p        p
                                                 U ≤  -------- =  ------------------------- =  ----------  ,
                                                       Y
                                                               Y
                                                                         Y
                                                                  ⁄
                                                               ⋅
                                                           1.65 1 5    0.33
                                                     cq Y
                                   then deliver X =  Y , else return to step 1.
                             The implementation of this example in MATLAB is left as an exercise.





                             4.3 Generating Continuous Random Variables




                             NNoorr malmal DD  ii isst sstt tributributi ributribut  n onon
                             Nor
                                 i
                               rmal mal
                                 DD
                             No
                                            ii
                                            ioon
                             The main MATLAB program has a function that will generate numbers from
                             the standard normal distribution, so we do not discuss any techniques for
                             generating random variables from the normal distribution. For the reader
                             who is interested in how normal random variates can be generated, most of
                             the references provided in Section 4.6 contain this information.
                              The MATLAB function for generating standard normal random variables
                             is called randn, and its functionality is similar to the function rand that was
                             discussed in the previous section. As with the uniform random variable U,
                             we can obtain a normal random variable X with mean   and variance σ  2   by
                                                                             µ
                             means of a transformation. Letting Z represent a standard normal random
                             variable (possibly generated from randn), we get the desired X from the rela-
                             tionship
                                                              ⋅
                                                        X =  Z σ +  . µ                     (4.8)


                             Expon e  ent eentnt nti  iaal aall l  DistrDistr DistrDistr i  ibutiobution  n
                                            ii
                             Expon
                                     ii
                             EExponxpon
                                                 nn
                                             butiobutio
                             The inverse transform method can be used to generate random variables
                             from the exponential distribution and serves as an example of this procedure.
                             The distribution function for an exponential random variable with parameter
                             λ   is given by
                            © 2002 by Chapman & Hall/CRC
   97   98   99   100   101   102   103   104   105   106   107