Posted By

aturlapaty on 08/11/14


Tagged

theory probability


Versions (?)

Simulation of Poisson Process


 / Published in: Python
 

URL: Poisson Process Simulation

A simple simulation of Poisson process: emission of particles from radio-active matter

  1. """
  2. Created on Sun Aug 10 15:24:18 2014
  3.  
  4. @author: Anish
  5.  
  6. Spyder Editor
  7.  
  8. """
  9. # Importing libraries
  10. import os
  11. os.system('cls')
  12. import numpy as np
  13. import matplotlib.pyplot as plt
  14. #import math
  15. #import time
  16.  
  17. #clf()
  18. Nlim = 100
  19. N = 145
  20. nvec = np.linspace(0.0, N-1, num=N)
  21. y1 = .2*sin(2.0*pi*nvec/N)
  22. y2 = .2*cos(2.0*pi*nvec/N)
  23.  
  24. plt.plot(y1, y2, linewidth=2.0);
  25. text(0, 0,'Radioactive Matter', fontsize = 12)
  26.  
  27. plt.xlim([-2,2])
  28. plt.ylim([-2,2])
  29.  
  30. #nvec = np.linspace(0.0, N-1, num=N)
  31. #y1 = sin(2.0*pi*nvec/N)
  32. #y2 = cos(2.0*pi*nvec/N)
  33. #text(-1, 0,'Atom', fontsize = 12)
  34. plt.plot(y1,y2)
  35. a = 1
  36. b = 2
  37. l = 2
  38.  
  39. # for loop for recursive plotting of poisson process
  40. for x in range(1, Nlim):
  41. s = np.random.poisson(l, 1)
  42. rloc = np.random.uniform(a,b,s)
  43. ph_loc= np.random.uniform(-pi,pi,s)
  44. x_loc = rloc*cos(ph_loc)
  45. y_loc = rloc*sin(ph_loc)
  46. line1, = plt.plot(x_loc,y_loc,'or')
  47. ax = gca()
  48. draw() # redraw the canvas
  49. pause(.7)
  50. ax.lines.remove(line1) # removes the most recent line

Report this snippet  

You need to login to post a comment.