为什么在matlab中用fmincon函数来解优化问题时!为什么我写的代码不显示x、fval、和flag的值求大神解答!
代码如下:%fminconfunctionmynamex0=20*rand(3,1);A=[];b=[];Aeq=[];beq=[];lb=[];beq=[];lb=[0...
代码如下:%fmincon
function myname
x0=20*rand(3,1);
A=[];b=[];
Aeq=[];beq=[];
lb=[];beq=[];
lb=[0;0;0];
ub=[20;20;20];
[x,fval,flag] = fmincon(@myobj,x0,A,b,Aeq,beq,lb,ub,@mycons);
function r = myobj(x)
r = 26*(x(1)-1)^2+50*x(2)+60*x(3);
r = -r;
function [c,ceq] = mycons(x)
c(1) = 10*x(1)^2+4*x(2)+3*x(3)^2-100;;
c(2) = 10-20*x(1)-x(2)-25*x(3);
c(3) = 20*x(1)+x(2)+25*x(3)-300;
ceq = [];
显示结果如下:
Warning: Trust-region-reflective method does not currently solve this type of problem,
using active-set (line search) instead.
> In fmincon at 439
In myname at 9
Local minimum found that satisfies the constraints.
Optimization completed because the objective function is non-decreasing in
feasible directions, to within the default value of the function tolerance,
and constraints were satisfied to within the default value of the constraint tolerance.
<stopping criteria details>
Active inequalities (to within options.TolCon = 1e-006):
lower upper ineqlin ineqnonlin
1 2 1 展开
function myname
x0=20*rand(3,1);
A=[];b=[];
Aeq=[];beq=[];
lb=[];beq=[];
lb=[0;0;0];
ub=[20;20;20];
[x,fval,flag] = fmincon(@myobj,x0,A,b,Aeq,beq,lb,ub,@mycons);
function r = myobj(x)
r = 26*(x(1)-1)^2+50*x(2)+60*x(3);
r = -r;
function [c,ceq] = mycons(x)
c(1) = 10*x(1)^2+4*x(2)+3*x(3)^2-100;;
c(2) = 10-20*x(1)-x(2)-25*x(3);
c(3) = 20*x(1)+x(2)+25*x(3)-300;
ceq = [];
显示结果如下:
Warning: Trust-region-reflective method does not currently solve this type of problem,
using active-set (line search) instead.
> In fmincon at 439
In myname at 9
Local minimum found that satisfies the constraints.
Optimization completed because the objective function is non-decreasing in
feasible directions, to within the default value of the function tolerance,
and constraints were satisfied to within the default value of the constraint tolerance.
<stopping criteria details>
Active inequalities (to within options.TolCon = 1e-006):
lower upper ineqlin ineqnonlin
1 2 1 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询