import numpy as npimport matplotlib.pyplot as plt
x = np.linspace(-np.pi, 2*np.pi, 1000)y = np.cos(x)
plt.figure(figsize=(10, 5))plt.plot(x, y, label='y=cos(x)')plt.axhline(y=1, color='r', linestyle='--', label='y=1')plt.axhline(y=-1, color='g', linestyle='--', label='y=-1')plt.axhline(y=0, color='b', linestyle='--', label='y=0')plt.fill_between(x, 0, y, where=(y>0), color='yellow', alpha=0.5, label='y>0')plt.fill_between(x, 0, y, where=(y<0), color='purple', alpha=0.5, label='y<0')
plt.legend()plt.xlabel('x')plt.ylabel('y')plt.title('Graph of y=cos(x) on the interval [-π, 2π]')plt.grid(True)plt.show()
x_y1 = np.arccos(1)x_yn1 = np.arccos(-1)x_y0 = np.pi
print("x for y = 1: ", x_y1)print("x for y = -1: ", x_yn1)print("x for y = 0: ", x_y0)
import numpy as np
import matplotlib.pyplot as plt
x = np.linspace(-np.pi, 2*np.pi, 1000)
y = np.cos(x)
plt.figure(figsize=(10, 5))
plt.plot(x, y, label='y=cos(x)')
plt.axhline(y=1, color='r', linestyle='--', label='y=1')
plt.axhline(y=-1, color='g', linestyle='--', label='y=-1')
plt.axhline(y=0, color='b', linestyle='--', label='y=0')
plt.fill_between(x, 0, y, where=(y>0), color='yellow', alpha=0.5, label='y>0')
plt.fill_between(x, 0, y, where=(y<0), color='purple', alpha=0.5, label='y<0')
plt.legend()
Finding the values of x for y(x) = 1, y(x) = -1, y(x) = 0plt.xlabel('x')
plt.ylabel('y')
plt.title('Graph of y=cos(x) on the interval [-π, 2π]')
plt.grid(True)
plt.show()
x_y1 = np.arccos(1)
x_yn1 = np.arccos(-1)
x_y0 = np.pi
print("x for y = 1: ", x_y1)
print("x for y = -1: ", x_yn1)
print("x for y = 0: ", x_y0)