Page 104 - Computational Statistics Handbook with MATLAB
P. 104

Chapter 4: Generating Random Variables                           91


                                % the theoretical density - see Chapter 5.
                                N = N/(h(2)-h(1))/n;
                                % Do the plots.
                                bar(h,N,1,'w')
                                hold on
                                plot(x,y)
                                hold off
                                xlabel('X')
                                ylabel('f(x) - Exponential')




                                        2
                                       1.8

                                       1.6
                                       1.4
                                      f(x) − Exponential  1
                                       1.2



                                       0.8
                                       0.6
                                       0.4
                                       0.2
                                        0
                                         0   0.5  1   1.5  2   2.5  3   3.5  4   4.5  5
                                                                X

                              F FI  IG URE G 4.  RE 4. 4  4
                               U
                              F F II  GU  RE RE 4. 4.  4
                                     4
                               GU
                              This shows  a  probability density  histogram of  the random variables generated  in
                              Example 4.6. We also superimpose the curve corresponding to the theoretical probability
                              density function with  λ =  2  . The histogram and the curve match quite well.


                             GGaamm ma
                               a
                             Ga
                             Gammm mama
                             In this section, we present an algorithm for generating a gamma random vari-
                             able with parameters  t λ,(  )  , where t is an integer. Recall that it has the follow-
                             ing distribution function





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