Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import math
- f = lambda x: 1/x
- a = -2
- b = -1
- n = 10
- s = 0
- h = (b - a) / n
- x = a
- for i in range(n + 1):
- print("x = {0}, y = {1}".format(round(x, 4), round(f(x), 4)))
- s += f(x)
- x += h
- Sn = h * (s - f(b))
- Si = h * (s - f(a))
- 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)))
- St = h * (s - f(a) - f(b) + (f(a) + f(b)) / 2)
- print("Sтрап = {0}".format(round(St, 4)))
- s1 = 0
- s2 = 0
- x = a + h
- for i in range(1, n):
- if (i % 2 == 0):
- s2 += f(x)
- else:
- s1 += f(x)
- x += h
- Ss = (b - a) / (3 * n) * (f(a) + f(b) + 4 * s1 + 2 * s2)
- 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