问题:max(-x1^2-x2)
s.t. x1^2+x2^2<= 9, x1+x2<1
请问如何书写解决这一问题的MATLAB代码?
我回来给你啊
我想想
很有趣
function M=max()
S=0;
syms x1 x2;
for x1=-3:0.001:3
for x2=-3:0.001:3
if (x1^2+x2^2<=9)|(x1+x2<=1)
T=-x1^2-x2;
if T>S S=T;
end
end
end
end
M=S;
你试试,我已经测试过了!正确!
MODEL:
MAX=-X1*X1-X2;
X1*X1+X2*X2<9;
X1+X2<1;
@FREE(X1);
@FREE(X2);
END
这个是上个题目的lingo模型解法!
Local optimal solution found at iteration: 13
Objective value: 3.000000
Variable Value Reduced Cost
X1 -0.2636344E-07 0.000000
X2 -3.000000 0.000000
Row Slack or Surplus Dual Price
1 3.000000 1.000000
2 0.000000 0.1666667
3 4.000000 0.000000
这个是report
非常感谢!
| 欢迎光临 数学建模社区-数学中国 (http://www.madio.net/) | Powered by Discuz! X2.5 |