Untitled

mail@pastecode.io avatar
unknown
plain_text
19 days ago
891 B
1
Indexable
Never
# Define the new piecewise function components
def f1(x):
    return -x - 5

def f2(x):
    return 5*x - 23

# Generate x values for each part
x1 = np.linspace(-10, -4, 100)  # for x <= -4
x2 = np.linspace(5, 10, 100)    # for x > 5

# Generate y values for each part
y1 = f1(x1)
y2 = f2(x2)

# Create the plot
plt.figure(figsize=(8, 6))
plt.plot(x1, y1, label=r'$f(x) = -x - 5$ for $x \leq -4$', color='blue')
plt.plot(x2, y2, label=r'$f(x) = 5x - 23$ for $x > 5$', color='red')

# Mark the boundary points
plt.plot(-4, f1(-4), 'bo')  # closed circle at x = -4
plt.plot(5, f2(5), 'ro', fillstyle='none')  # open circle at x = 5

# Add details to the plot
plt.axhline(0, color='black',linewidth=1)
plt.axvline(0, color='black',linewidth=1)
plt.title('Graph of the Piecewise Function')
plt.xlabel('x')
plt.ylabel('f(x)')
plt.legend(loc='upper left')
plt.grid(True)

# Show the plot
plt.show()
Leave a Comment