matlab的非线性优化问题,我自己编了一下,有问题,我把我的程序发上来,希望大虾帮我看下,谢了

2024-12-14 12:12:23
推荐回答(2个)
回答1:

%约束条件
function[c,ceq]=nonlcon(x)
c(1)=(863.4*x(1))/x(2)-x(3).^3;
c(2)=x(2)+x(2)/x(1)-120;
ceq=[];
---------------
>> funn=@(x)x(2)*x(3)+(x(2)*x(3))/x(1);
>> vlb=[0.25;18;1.5];%x1,x2,x3的下限值
vub=[1;100;6];%x1,x2,x3的上限值
x0=[0.9;50;2.5];%x1,x2,x3的初始值
[x,fval,exitflagn] = fmincon(funn,x0,[],[],[],[],vlb,vub,@nonlcon)
Warning: Trust-region-reflective algorithm does not solve this type of problem,
using active-set algorithm. You could also try the interior-point or sqp
algorithms: set the Algorithm option to 'interior-point' or 'sqp' and rerun.
For more help, see Choosing the Algorithm in the documentation.
> In fmincon at 472

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.



Active inequalities (to within options.TolCon = 1e-006):
lower upper ineqlin ineqnonlin
2 1 1

x =

1.0000
18.0000
3.6334

fval =

130.8024

exitflagn =

1

>>

回答2:

换用这个函数进行求解:
[x,fval,attainfactor,exitflag,output]=fgoalattain(@goalfunction,x0,goal,weight,A,b,Aeq,beq,lb,ub,@nonlcon);