Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from math import *
- import matplotlib.pyplot as plt
- def integrate(a, b, n, f):
- h = float(b - a) / n
- result = 0.5 * (f(a) + f(b))
- for i in range(1, n):
- result += f(a + i * h)
- result *= h
- return result
- def check(a, b, f,t):
- prev, n = 0, 1
- while True:
- next = integrate(a, b, n, f)
- if abs(next - prev) < t:
- return next
- n = n * 2
- prev = next
- f = lambda x: (x ** 3) * (exp(2 * x))
- print(check(0, 1, f, 0.00001))
- def fi(x):
- return (e**x-e**(-x))/2
- def si(x):
- return (x+1)/(x**2+x+1)
- def f2(x,t):
- return fi(t/(1+x**2)+0.01*x)*si(x)
- a2, b2, c, d,m = 0, pi/2, 0.5, 1.5, 10
- def F(t):
- return check(a2, b2, lambda x: f2(x, t), 0.0001)
- t = [a2 + i*(d-c)/m for i in range(m+1)]
- print(*map(lambda x: f"F({x}) = {F(x):.4f}", t), sep="\n")
- plt.plot(t,list(map(F, t)))
- plt.legend()
- plt.grid()
- plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement