[text] uhfasr

Viewer

  1. import matplotlib.pyplot as plt
  2. import numpy as np
  3.  
  4. a = 1 + np.pi/2
  5.  
  6. def f(x):
  7.     return np.where(x <= np.pi/2, np.sin(x), a - x)
  8.  
  9. x_values = np.linspace(0, 4, 1000)
  10. y_values = f(x_values)
  11.  
  12. plt.plot(x_values, y_values, label=r'$f(x)$')
  13. plt.axvline(x=np.pi/2, color='red', linestyle='--', label=r'$x=\frac{\pi}{2}$', linewidth=1)
  14. plt.axhline(y=1, color='green', linestyle='--', label=r'$y=1$', linewidth=1)
  15. plt.axhline(y=a - np.pi/2, color='blue', linestyle='--', label=r'$y=a-\frac{\pi}{2}$', linewidth=1)
  16.  
  17. plt.xlabel('x')
  18. plt.ylabel('f(x)')
  19. plt.title('Graph of f(x)')
  20. plt.legend()
  21. plt.grid(True)
  22. plt.show()
  23.  

Editor

You can edit this paste and save as new:


File Description
  • uhfasr
  • Paste Code
  • 10 Dec-2023
  • 631 Bytes
You can Share it: