Advertisement
Guest User

Untitled

a guest
Oct 15th, 2019
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.46 KB | None | 0 0
  1. import numpy as np
  2. from random import choice
  3. import matplotlib.pyplot as plt
  4. al = [(x,x+1/15) for x in np.arange(0,1,1/15) ]
  5. def ex(N):
  6. n = 0
  7. for i in range(N):
  8. x = np.random.uniform(0,1)
  9. a1,a2,a3 = choice(al),choice(al),choice(al)
  10. if (x>a1[0] and x<a1[1]) or (x>a2[0] and x<a2[1]) or (x>a3[0] and x<a3[1]):
  11. n += 1
  12. return n/N
  13. a1 = [1,100,1000,10000,100000]
  14. a2 = [ex(i) for i in a1]
  15. plt.plot(a1,a2)
  16. plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement