home *** CD-ROM | disk | FTP | other *** search
/ Math Solutions 1995 October / Math_Solutions_CD-ROM_Walnut_Creek_October_1995.iso / pc / mac / mathpad2 / examples / poisson < prev    next >
Encoding:
Text File  |  1994-06-11  |  782 b   |  32 lines

  1. -- Generate Poisson random inter-event times.
  2. -- Since the Poisson distribution is a simple exponential, the inverse of its integral can be used to transform the uniform random distribution.
  3.  
  4. poissonrand(aveper) = -ln(rand(1))*aveper
  5.  
  6. -- Check the distribution by accumulating a histogram.
  7. include ":incl:histogram"
  8.  
  9. -- make an array of random inter-event times
  10. nevents = 600
  11. aveper = 2.5
  12. dt[i] = poissonrand(aveper) dim[nevents]
  13.  
  14. -- accumulate a histogram of number of events vs. inter-event time.
  15. nbins = 40
  16. histo(dt,Xmin,Xmax,nbins):
  17. total:596.000
  18.  
  19. plot bins
  20. label mean:2.503
  21. label aveper:2.500
  22. Xmin=0; Xmax=5*aveper
  23. Ymin=0;
  24.  
  25. -- plot the continuous Poisson distribution
  26. poisson(t) = exp(-t/aveper)
  27.  
  28. plot bin1*poisson(X)
  29.  
  30. bint = (Xmax-Xmin)/nbins
  31. bin1 = nevents*(1-poisson(bint))
  32.