Untitled
unknown
plain_text
5 months ago
1.5 kB
2
Indexable
# Adjusting the graph to a proper 1-5 range for x and y axes # Define the x-values to range from 1 to 5 x_vals = np.linspace(1, 5, 400) # Adjust the corresponding y-values for each equation y1_vals = 5 - 2*x_vals # y = 5 - 2x y2_vals = 5 - 2*x_vals**2 # y = 5 - 2x² y3_vals = 3*x_vals**2 # y = 3x² y4_positive_vals = np.sqrt(5 - 2*x_vals**2) # y² = 5 - 2x² (positive part) y4_negative_vals = -np.sqrt(5 - 2*x_vals**2) # y² = 5 - 2x² (negative part) y5_vals = np.abs(5 - 9*x_vals) # y = |5 - 9x| # Set up the figure and axis, with both axes going from 1 to 5 fig, ax = plt.subplots(figsize=(8, 8)) # Plot the equations in the 1-5 range ax.plot(x_vals, y1_vals, label="1. y = 5 - 2x", color="blue") ax.plot(x_vals, y2_vals, label="2. y = 5 - 2x²", color="green") ax.plot(x_vals, y3_vals, label="3. y = 3x²", color="red") ax.plot(x_vals, y4_positive_vals, label="4. y² = 5 - 2x² (positive)", color="purple") ax.plot(x_vals, y4_negative_vals, label="4. y² = 5 - 2x² (negative)", color="purple", linestyle="--") ax.plot(x_vals, y5_vals, label="5. y = |5 - 9x|", color="orange") # Set the axis limits to 1-5 for both x and y ax.set_xlim(1, 5) ax.set_ylim(1, 5) # Add grid, x and y axis labels ax.axhline(0, color='black',linewidth=1) ax.axvline(0, color='black',linewidth=1) ax.set_xlabel("x") ax.set_ylabel("y") # Add a title and legend ax.set_title("Graphs of Equations 1-5 in x and y range from 1 to 5") ax.legend() # Show the plot plt.show()
Editor is loading...
Leave a Comment