我有两个不等式
y< = - 1/2 * x和y> = -2/5 * x,受约束条件-20< = x< = 0。
有没有人知道我如何让这些不平等的所有解决方案显示(或更好地计算)?
感谢阅读。
答案 0 :(得分:0)
在可行区域中存在无限多的实值解。所以也许你的意思是指定你只想要整数值的可行点。
restart:
interface(warnlevel=0):
ineqs := { y<=-1/2*x, y>=-2/5*x }:
feasP := plots:-inequal (ineqs, x=-20..0, y=0..10, nolines ):
isols := { seq( seq({x=i} union s, s in {isolve( eval(ineqs,x=i) )}),
i=-20..0 ) };
{{x = -20, y = 8}, {x = -20, y = 9}, {x = -20, y = 10},
{x = -19, y = 8}, {x = -19, y = 9}, {x = -18, y = 8},
{x = -18, y = 9}, {x = -17, y = 7}, {x = -17, y = 8},
{x = -16, y = 7}, {x = -16, y = 8}, {x = -15, y = 6},
{x = -15, y = 7}, {x = -14, y = 6}, {x = -14, y = 7},
{x = -13, y = 6}, {x = -12, y = 5}, {x = -12, y = 6},
{x = -11, y = 5}, {x = -10, y = 4}, {x = -10, y = 5},
{x = -9, y = 4}, {x = -8, y = 4}, {x = -7, y = 3},
{x = -6, y = 3}, {x = -5, y = 2}, {x = -4, y = 2},
{x = -2, y = 1}, {x = 0, y = 0}}
nops(isols);
29
ptsP := plots:-pointplot( [ seq( eval([x,y],s), s in isols ) ],
color=red, symbol=solidcircle ):
plots:-display( feasP, ptsP );
如果这是家庭作业,那么教师可能会让你迭代整数y值(而不是叫isolve
,比如说)。
isols := { seq( seq({x=i,y=j}, j=ceil(-2/5*i)..-1/2*i), i=-20..0 ) };