Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- xg = []
- yg = []
- def experiment(N):
- cnt = 0
- for _ in range(N):
- x = uniform(-6,6)
- y = uniform(-6,6)
- if x >= 0 and y >= 0 or sqrt(x**2 + y**2) <= 1:
- cnt += 1
- if N == 100000:
- xg.append(x)
- yg.append(y)
- return cnt / N
- print(experiment(100000))
- x = [i for i in range(1, 100000, 1000)]
- y = [experiment(i) for i in x]
- plt.plot(x[3:],y[3:])
- plt.title('PLOT')
- plt.plot ([1, 100000],[0.2663,0.2663], 'r-')
- plt.show()
- #В следующую клетку
- rectangle = plt.Rectangle((-6,-6),width = 12, height = 12)
- ax=plt.gca()
- ax.add_patch(rectangle)
- plt.plot(xg,yg,linestyle="",color="red",marker="o")
- plt.xlim(xmin = -10,xmax = 10)
- plt.ylim(ymin = -10,ymax = 10)
- plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement