我无法设置最大值和最小值以遮蔽可行区域。请看一下我的代码,让我知道我哪里出错了,谢谢。
import numpy as np
import matplotlib.pyplot as plt
'''
Let x = Square Tables and y = Round Tables
Minimize: z = 40x + 60y
Subject to: x + y >= 5 or y1 = 5 - x BLUE
x + y <= 10 or y2 = 10 - x ORANGE
x >= y + 3 or y3 = x - 3 GREEN
'''
x = np.linspace(0, 20, 100)
y1 = 5 - x
y2 = 10 - x
y3 = x - 3
plt.plot(x, y1)
plt.plot(x, y2)
plt.plot(x, y3)
plt.xlim((0, 12))
plt.ylim((0, 12))
plt.xlabel(r'$Square Tables$')
plt.ylabel(r'$Round Tables$')
y4 = np.minimum(y1, y2)
y5 = np.maximum(y1, y3)
plt.fill_between(x, y4, y5, color='grey', alpha=0.5)
答案 0 :(得分:0)
你可以这样做:
x = np.linspace(0, 20, 100)
y1 = 5 - x
y2 = 10 - x
y3 = x - 3
plt.plot(x, y1)
plt.plot(x, y2)
plt.plot(x, y3)
plt.xlim((0, 12))
plt.ylim((0, 12))
plt.xlabel(r'$Square Tables$')
plt.ylabel(r'$Round Tables$')
y5 = np.minimum(y2, y3)
plt.fill_between(x, y1, y5,where=y5 >= y1, color='grey', alpha=0.5)