Advertisement
Guest User

Untitled

a guest
Nov 18th, 2019
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. import random as rand
  2. import matplotlib.pyplot as plt
  3. import math
  4.  
  5. def er():
  6. x = 0
  7. for i in range(2):
  8. x+= rand.expovariate(6)
  9. return x
  10.  
  11. tc = 0
  12. N = 10000
  13. k = 0
  14. u =[]
  15. lo = 1000
  16. vo = 1000
  17. check = 1
  18. NG = []
  19. lG = []
  20. vG = []
  21. while check:
  22. NG.append(N)
  23. while k<N:
  24. u.append(er())
  25. tc+=u[k]
  26. k+=1
  27. mu = tc/N
  28. sum2 = 0
  29. for i in range(N):
  30. sum2+=(u[i] - mu)**2
  31. qu = (sum2/N)**(1/2)
  32. ln = 1/mu
  33. vn = qu/mu
  34. lG.append(ln)
  35. vG.append(vn)
  36. if math.fabs((ln - lo)/lo)>0.01 or math.fabs((vn - vo)/vo)>0.01:
  37. lo = ln
  38. vo=vn
  39. N*=2
  40. else:
  41. check = 0
  42.  
  43. lr = [1 for i in range(len(NG))]
  44. vr = [1 for i in range(len(NG))]
  45. print(u)
  46. plt.figure(1)
  47. plt.plot(NG,lG)
  48. plt.plot(NG,lr)
  49. plt.figure(2)
  50. plt.plot(NG,vG)
  51. plt.plot(NG,vr)
  52. plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement