Advertisement
StoneHaos

math9

Dec 25th, 2020
1,209
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.92 KB | None | 0 0
  1. import math
  2.  
  3. f = lambda x: 1/x
  4.  
  5. a = -2
  6. b = -1
  7. n = 10
  8.  
  9. s = 0
  10. h = (b - a) / n
  11. x = a
  12. for i in range(n + 1):
  13.     print("x = {0}, y = {1}".format(round(x, 4), round(f(x), 4)))
  14.     s += f(x)
  15.     x += h
  16.  
  17. Sn = h * (s - f(b))
  18. Si = h * (s - f(a))
  19. print("Sнед = {0}*({1}) = {2}, Sизб = {0}*({3}) = {4}".format(round(h, 4), round(s - f(b), 4), round(Sn, 4), round(s - f(a), 4), round(Si, 4)))
  20. St = h * (s - f(a) - f(b) + (f(a) + f(b)) / 2)
  21. print("Sтрап = {0}".format(round(St, 4)))
  22.  
  23. s1 = 0
  24. s2 = 0
  25. x = a + h
  26. for i in range(1, n):
  27.     if (i % 2 == 0):
  28.         s2 += f(x)
  29.     else:
  30.         s1 += f(x)
  31.     x += h
  32.  
  33. Ss = (b - a) / (3 * n) * (f(a) + f(b) + 4 * s1 + 2 * s2)
  34. print("{0}({1}+{2}+4({3})+2({4}) = {0}({5}+{6}+{7}) = {0}*{8} = {9}".format(round((b - a) / (3 * n), 4), round(f(a), 4), round(f(b), 4), round(s1, 4), round(s2, 4), round(f(a) + f(b), 4), round(4 * s1, 4), round(2 * s2, 4), round(f(a) + f(b) + 4 * s1 + 2 * s2, 4), round(Ss, 4)))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement