import numpy as npimport matplotlib.pyplot as plt
def piecewise_function(x):if x <= -2:return xelse:return x + 6
x = np.linspace(-5, 5, 100)y = [piecewise_function(i) for i in x]
plt.plot(x, y)plt.title('Piecewise Function: y={x, если x≤-2; x+6, если x>-2')plt.xlabel('x')plt.ylabel('y')plt.grid(True)plt.show()
import numpy as np
import matplotlib.pyplot as plt
def piecewise_function(x):
if x <= -2:
return x
else:
return x + 6
x = np.linspace(-5, 5, 100)
y = [piecewise_function(i) for i in x]
plt.plot(x, y)
plt.title('Piecewise Function: y={x, если x≤-2; x+6, если x>-2')
plt.xlabel('x')
plt.ylabel('y')
plt.grid(True)
plt.show()