Untitled
unknown
plain_text
4 months ago
1.4 kB
5
Indexable
import matplotlib.pyplot as plt import numpy as np # Define the range of x and y values x_vals = np.linspace(0, 50, 400) y_vals = np.linspace(0, 50, 400) # Constraints y1 = (100 - x_vals) / 5 # Line for 1x + 5y = 100 y2 = (66 - 3 * x_vals) / 2 # Line for 3x + 2y = 66 y3 = (136 - 8 * x_vals) / 2 # Line for 8x + 2y = 136 # Profit lines P34 = (34 - 2 * x_vals) / 3 # Line for P = 34 P60 = (60 - 2 * x_vals) / 3 # Line for P = 60 P64 = (64 - 2 * x_vals) / 3 # Line for P = 64 P74 = (74 - 2 * x_vals) / 3 # Line for P = 74 P80 = (80 - 2 * x_vals) / 3 # Line for P = 80 # Plot the constraints plt.figure(figsize=(10, 8)) plt.plot(x_vals, y1, label='1x + 5y = 100', color='blue') plt.plot(x_vals, y2, label='3x + 2y = 66', color='green') plt.plot(x_vals, y3, label='8x + 2y = 136', color='red') # Plot the profit lines plt.plot(x_vals, P34, '--', label='P = 34$', color='purple') plt.plot(x_vals, P60, '--', label='P = 60$', color='orange') plt.plot(x_vals, P64, '--', label='P = 64$', color='brown') plt.plot(x_vals, P74, '--', label='P = 74$', color='pink') plt.plot(x_vals, P80, '--', label='P = 80$', color='cyan') # Set plot limits plt.xlim(0, 50) plt.ylim(0, 50) # Add labels and legend plt.xlabel('x (Crêpes)') plt.ylabel('y (Cakes)') plt.title('Constraints and Profit Lines') plt.legend(loc='upper right') plt.grid() # Show the plot plt.show()
Editor is loading...
Leave a Comment