Advertisement
edcoder000

44444

Dec 14th, 2019
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.92 KB | None | 0 0
  1. from math import *
  2. import matplotlib.pyplot as plt
  3.  
  4. def integrate(a, b, n, f):
  5.     h = float(b - a) / n
  6.     result = 0.5 * (f(a) + f(b))
  7.     for i in range(1, n):
  8.         result += f(a + i * h)
  9.     result *= h
  10.     return result
  11.  
  12. def check(a, b, f,t):
  13.     prev, n = 0, 1
  14.     while True:
  15.         next = integrate(a, b, n, f)
  16.         if abs(next - prev) < t:
  17.             return next
  18.         n = n * 2
  19.         prev = next
  20. f = lambda x: (x ** 3) * (exp(2 * x))
  21.  
  22. print(check(0, 1, f, 0.00001))
  23.  
  24. def fi(x):
  25.     return (e**x-e**(-x))/2
  26.  
  27. def si(x):
  28.     return (x+1)/(x**2+x+1)
  29.  
  30. def f2(x,t):
  31.     return fi(t/(1+x**2)+0.01*x)*si(x)
  32.  
  33. a2, b2, c, d,m = 0, pi/2, 0.5, 1.5, 10
  34.  
  35. def F(t):
  36.     return check(a2, b2, lambda x: f2(x, t), 0.0001)
  37.  
  38. t = [a2 + i*(d-c)/m for i in range(m+1)]
  39.  
  40. print(*map(lambda x: f"F({x}) = {F(x):.4f}", t), sep="\n")
  41.  
  42.  
  43. plt.plot(t,list(map(F, t)))
  44. plt.legend()
  45. plt.grid()
  46. plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement