Advertisement
F4ntomas

Informatics_and_prog_3.2

May 16th, 2022
776
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.73 KB | None | 0 0
  1. from cmath import asin
  2. import math
  3. import matplotlib.pyplot as plt
  4. import numpy as np
  5. import sympy as sym
  6. from sympy.stats import Arcsin
  7. from scipy.optimize import minimize, minimize_scalar, fmin
  8. from sympy.sets import *
  9. from sympy.calculus.util import continuous_domain
  10. from sympy import Symbol, limit, S
  11. from sympy.functions import asin
  12.  
  13.  
  14.  
  15. def f(x) -> float:
  16.     """Функция"""
  17.     return ((x**2/2)-1)
  18.  
  19.  
  20. # Постройка графика    
  21. fig, ax = plt.subplots()
  22. x = np.linspace(-10,10,50)
  23. # функция f(x) = x^2/2-1
  24. y = ((x**2/2)-1)
  25. ax = ax.plot(x, y, "b-")
  26. ax = plt.gca()
  27. ax.spines['left'].set_position("center")
  28. ax.spines['bottom'].set_position('center')
  29. ax.spines['top'].set_visible(False)
  30. ax.spines['right'].set_visible(False)
  31. ax.set_xlabel("Y", fontsize=15, color='blue', labelpad=120) # +
  32. ax.set_ylabel("X", fontsize=15, color='orange', labelpad=140, rotation=0)
  33. plt.title(r'функция $y = x^2$/2-1')
  34.  
  35. z = Symbol('z')
  36. # найдем точки пересечения с осью Ox
  37. roots = sym.solve((z**2/2)-1)
  38.  
  39. print(f'Верхний предел = {roots[1]}\nНижний предел = {roots[0]}')
  40. # производная
  41. derivative = sym.diff((z**2/2)-1)
  42.  
  43. a = roots[0]
  44. b = roots[1]
  45.  
  46. # (1+derivative**2)**(1/2)
  47. # Нахождение длины дуги по форумле integral(a,b) sqrt(1+derivate^2) dx
  48. # https://mathforyou.net/online/calculus/arclen/cartesian/
  49. # Дока по интегралам https://docs.sympy.org/latest/modules/integrals/integrals.html
  50. length = sym.integrate(sym.sqrt(1+derivative**2), (z, a, b))
  51. print(f'Длина дуги = {length}')
  52.  
  53. #plt.fill_between(x, y, where = (y >= -1) & (x <= np.sqrt(2)) & (x >= -np.sqrt(2)),color='cyan')
  54.  
  55. plt.show()
  56.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement