Advertisement
bogdanpashtet

viichi

May 13th, 2021
531
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 cos, sin, pi
  2. from scipy import integrate
  3. import numpy as np
  4.  
  5.  
  6. def f(x):
  7.     return x * cos(x) ** 2
  8.  
  9.  
  10. def df(x):
  11.     return -2 * x * sin(x) * cos(x) + cos(x) ** 2
  12.  
  13.  
  14. a = 0
  15. b = pi / 2
  16. s = 0
  17.  
  18. # Задание №1 Пункты №1-3
  19.  
  20. # J = integrate.quad(f, a, b)
  21. #
  22. # print(f"J = {J}\n")
  23. #
  24. # for k in range(1, 16):
  25. #     s = 0
  26. #     x0 = a
  27. #     n = 10 ** k
  28. #     h = (b - a)/n
  29. #     for i in range(n):
  30. #         s += f(a + i * h)
  31. #     s *= h
  32. #     print(f"{k:d}            |  {s:.15f}   |    {abs(J[0] - s)}")
  33.  
  34. # Задание №1 Пункты №4-6
  35.  
  36. # print(f"Производная заданной функции: -2*x*sin(x)*cos(x) + cos(x)**2\n")
  37. # dif = df(a)
  38. # print(f"D = df(a) = {dif}\n")
  39. #
  40. # for k in range(1, 16):
  41. #     h = (b - a)/(10 ** k)
  42. #     x0 = a + h
  43. #     s = (f(x0 + h) - f(x0 - h)) / 2 / h
  44. #     print(f"{k:d}            |  {s:.15f}  |   {abs(dif - s)}")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement