fork download
  1. import numpy as np
  2. import matplotlib.pyplot as plt
  3. from matplotlib.patches import Rectangle
  4.  
  5. # Функция y=(2-x)/(3+x)
  6. def func(x):
  7. return (2 - x) / (3 + x)
  8.  
  9. # Создаем массив значений x
  10. x_values = np.linspace(-5, 5, 400)
  11. # Вычисляем соответствующие значения y
  12. y_values = func(x_values)
  13.  
  14. # Построение графика функции
  15. plt.plot(x_values, y_values, label='$y = \\frac{2 - x}{3 + x}$')
  16. plt.xlabel('x')
  17. plt.ylabel('y')
  18. plt.title('График функции $y = \\frac{2 - x}{3 + x}$')
  19. plt.grid(True)
  20. plt.axhline(0, color='black', linewidth=0.5)
  21. plt.axvline(0, color='black', linewidth=0.5)
  22.  
  23. # Построение круга
  24. circle = plt.Circle((0, 0), 1, color='blue', alpha=0.5)
  25. plt.gca().add_patch(circle)
  26.  
  27. # Вписываем квадрат в круг
  28. square = Rectangle((-0.5, -0.5), 1, 1, color='yellow')
  29. plt.gca().add_patch(square)
  30.  
  31. # Устанавливаем пределы для осей x и y
  32. plt.xlim(-5, 5)
  33. plt.ylim(-5, 5)
  34.  
  35. # Отображаем легенду
  36. plt.legend()
  37.  
  38. # Показываем график
  39. plt.show()
  40.  
Success #stdin #stdout 2.16s 56848KB
stdin
Standard input is empty
stdout
Standard output is empty