Untitled
unknown
plain_text
6 months ago
850 B
4
Indexable
import numpy as np import matplotlib.pyplot as plt # Define the x range for one period of y = 5 * cos(2x) x = np.linspace(0, np.pi, 100) y = 5 * np.cos(2 * x) # Plot the function plt.figure(figsize=(8, 4)) plt.plot(x, y, label=r'$y = 5 \cos(2x)$', color='blue') plt.xlabel(r'$x$') plt.ylabel(r'$y$') plt.title('Graph of $y = 5 \cos(2x)$ for one period') plt.axhline(0, color='black',linewidth=0.5) plt.axvline(0, color='black',linewidth=0.5) plt.grid(True, linestyle='--', alpha=0.7) plt.legend(loc="upper right") # Show key points x_key_points = [0, np.pi / 4, np.pi / 2, 3 * np.pi / 4, np.pi] y_key_points = 5 * np.cos(2 * np.array(x_key_points)) plt.scatter(x_key_points, y_key_points, color='red') for (xk, yk) in zip(x_key_points, y_key_points): plt.text(xk, yk, f'({xk:.2f}, {yk:.1f})', ha='right') plt.show()
Editor is loading...
Leave a Comment