Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2019
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 KB | None | 0 0
  1. xg = []
  2. yg = []
  3. def experiment(N):
  4. cnt = 0
  5. for _ in range(N):
  6. x = uniform(-6,6)
  7. y = uniform(-6,6)
  8. if x >= 0 and y >= 0 or sqrt(x**2 + y**2) <= 1:
  9. cnt += 1
  10. if N == 100000:
  11. xg.append(x)
  12. yg.append(y)
  13. return cnt / N
  14. print(experiment(100000))
  15. x = [i for i in range(1, 100000, 1000)]
  16. y = [experiment(i) for i in x]
  17. plt.plot(x[3:],y[3:])
  18. plt.title('PLOT')
  19. plt.plot ([1, 100000],[0.2663,0.2663], 'r-')
  20. plt.show()
  21. #В следующую клетку
  22. rectangle = plt.Rectangle((-6,-6),width = 12, height = 12)
  23. ax=plt.gca()
  24. ax.add_patch(rectangle)
  25. plt.plot(xg,yg,linestyle="",color="red",marker="o")
  26. plt.xlim(xmin = -10,xmax = 10)
  27. plt.ylim(ymin = -10,ymax = 10)
  28. plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement