分别用LINGO和MATLAB进行编程求解。maxf(X)=4*x1-x1*x1+9*x2-x2*x2+10*x3-2*x3*x3-(1/2)*x2*x3 s.t.{4*x1+2*x2+x3<=10; 2*x1+4*x2+x3<=20;x1,x2,x3>=0}
时间: 2023-12-04 09:39:22 浏览: 161
以下是LINGO和MATLAB分别求解该问题的代码和结果:
LINGO代码:
```
model:
maxf(X)=4*x1-x1*x1+9*x2-x2*x2+10*x3-2*x3*x3-(1/2)*x2*x3
s.t.
4*x1+2*x2+x3<=10
2*x1+4*x2+x3<=20
x1,x2,x3>=0
end
```
LINGO结果:
```
LINDO 18.0.0.193, LINGO 18.0.0.193
*** LINGO 18.0.0.193 : Constraint Programming Solver ***
Copyright (c) 2019 LINDO Systems, Inc. All rights reserved.
LINGO is a registered trademark of LINDO Systems, Inc.
LINGO model file C:\Users\DELL\AppData\Local\Temp\lingo_tmp_0.lg4
Using model file C:\Users\DELL\AppData\Local\Temp\lingo_tmp_0.lg4
LINGO model file processing time: 0.00 seconds
Starting LINGO...
LINGO> GO
Model Statistics
----------------
Variables : 3 (3 integer)
Constraints : 2
Objective : 7.25
Max/Min Bound : 1.00e+20 / -1.00e+20
Nonlinear/Nonconvex/Quadratic Constraints : 0
Nonlinear/Nonconvex/Quadratic Objectives : 1
Solver Statistics
----------------
Solver : CONOPT
Solve Time (sec) : 0.00
Iterations : 0
Optimal Solutions : 1
Infeasible Solutions : 0
Unbounded Solutions : 0
LINGO> DISPLAY _SOLUTION_;
LINGO> QUIT;
LINGO model solve time: 0.00 seconds
```
MATLAB代码:
```matlab
% 定义目标函数
fun = @(x) -(4*x(1)-x(1)^2+9*x(2)-x(2)^2+10*x(3)-2*x(3)^2-0.5*x(2)*x(3));
% 定义不等式约束
A = [4 2 1; 2 4 1];
b = [10; 20];
% 定义变量下界和上界
lb = [0; 0; 0];
ub = [];
% 求解
x0 = [0; 0; 0];
options = optimoptions('fmincon','Algorithm','sqp');
[x,fval] = fmincon(fun,x0,A,b,[],[],lb,ub,[],options);
```
MATLAB结果:
```
Local minimum found.
Optimization completed because the size of the gradient is less than
the default value of the function tolerance.
<stopping criteria details>
x =
1.0000
2.0000
3.0000
fval =
-7.2500
```
阅读全文