Advertisement
Guest User

Untitled

a guest
Oct 14th, 2019
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. from random import random
  2. import math
  3. import matplotlib
  4. import matplotlib.pyplot as plt
  5. %matplotlib inline
  6.  
  7.  
  8. def acute(a, b, c):
  9. cosa = (a**2 - b**2 + c**2)/(2 * a * c)
  10. cosb = (b**2 - a**2 + c**2)/(2 * b * c)
  11. cosc = (b**2 - c**2 + a**2)/(2 * b * a)
  12. if cosa > 1 or cosa < -1 or cosb > 1 or cosb < -1 or cosc > 1 or cosc < -1:
  13. return False
  14. if (math.acos(cosa) < 1.5708) and (math.acos(cosb) < 1.5708) and (math.acos(cosc) < 1.5708):
  15. return True
  16. else:
  17. return False
  18.  
  19. def triangle(N):
  20. n = 0
  21. for i in range(N):
  22. x = random()
  23. y = random()
  24. if x < y:
  25. a = x
  26. b = y - x
  27. c = 1 - y
  28. else:
  29. a = y
  30. b = x - y
  31. c = 1 - x
  32. # Condition:
  33. if b < a > c:
  34. if (a < b + c) and acute(a, b, c):
  35. n += 1
  36. elif (a < b > c) and acute(a, b, c):
  37. if b < a + c:
  38. n += 1
  39. else:
  40. if (c < a + c) and acute(a, b, c):
  41. n += 1
  42. return n/N
  43. N = 10000
  44. print("Answer:")
  45. print(triangle(N))
  46.  
  47. x = [i for i in range(1, 10000, 100)]
  48. y1 = []
  49.  
  50. for i in range(1, 1000, 10):
  51. y1.append(A(i))
  52.  
  53.  
  54. plt.plot(x[2:], y1[2:])
  55. plt.title('PLOT')
  56. plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement