作业帮 > 综合 > 作业

matlab解决约束非线性规划问题

来源:学生作业帮 编辑:作业帮 分类:综合作业 时间:2024/05/16 19:52:27
matlab解决约束非线性规划问题
myfun.m
function f=myfun(x)
f=x(1)*x(13)+x(2)*x(14)+x(3)*x(15)+x(25)+1.697*(x(4)*x(16)+...
x(5)*x(17)+x(6)*x(18)+x(26))+0.575*(x(7)*x(19)+x(8)*x(20)...
+x(9)*x(21)+x(27))+0.723*(x(10)*x(22)+x(11)*x(23)+x(12)*x(24));
mycon.m
function [c,ceq]=mycon(x)
c(1)=6-x(25)-x(1)*x(13)-x(2)*x(14)-x(3)*x(15);
c(2)=3-x(26)-x(4)*x(16)-x(5)*x(17)-x(6)*x(18);
c(3)=1-x(27)-x(7)*x(19)-x(8)*x(20)-x(9)*x(21);
c(4)=10-x(10)*x(22)-x(11)*x(23)-x(12)*y(24);
ceq(1)=x(1)*x(13)+x(4)*x(16)+x(7)*x(19)+x(10)*x(22)-8;
ceq(2)=x(2)*x(14)+x(5)*x(17)+x(8)*x(20)+x(11)*x(23)-1;
ceq(3)=x(3)*x(15)+x(6)*x(18)+x(9)*x(21)+x(12)*x(24)-8;
输入:
>> x0=zeros(27,1);lb=zeros(27,1);
>> [x,fval]=fmincon(-@myfun,x0,[],[],[],[],lb,[],@mycon)
回车后:Function 'uminus' is not defined for values of class 'function_handle'.
Error in ==> uminus at 13
[varargout{1:nargout}] = builtin('uminus',varargin{:});
[x,fval]=fmincon(-@myfun,x0,[],[],[],[],lb,[],@mycon)
其中@myfun前去掉“-”试试
如果你是要求最大值,请在myfun中的f前加负号
再问: 试了,还是出现如下错误: > In fmincon at 260 ??? Error using ==> fmincon FMINCON cannot continue because user supplied nonlinear constraint function failed with the following error: Undefined command/function 'y'.