求MATLAB大神给指出程序错误!function y = objfun(x)y = 1/x(1) + 2/x(2) + 4/x(3) + 6/x(4)function [c,ceq]=confun(x)c = [x(1)+x(2)+3*x(3)+3*x(4)-2;x(1)+2*x(2)+2*x(3)+x(4)-1.8];ceq = []x0 = [0,0,0,0]lb = [0.2,0.2,0.2,0.2]ub = []options = optimse
来源:学生作业帮助网 编辑:六六作业网 时间:2024/12/25 03:41:57
求MATLAB大神给指出程序错误!function y = objfun(x)y = 1/x(1) + 2/x(2) + 4/x(3) + 6/x(4)function [c,ceq]=confun(x)c = [x(1)+x(2)+3*x(3)+3*x(4)-2;x(1)+2*x(2)+2*x(3)+x(4)-1.8];ceq = []x0 = [0,0,0,0]lb = [0.2,0.2,0.2,0.2]ub = []options = optimse
求MATLAB大神给指出程序错误!
function y = objfun(x)
y = 1/x(1) + 2/x(2) + 4/x(3) + 6/x(4)
function [c,ceq]=confun(x)
c = [x(1)+x(2)+3*x(3)+3*x(4)-2;x(1)+2*x(2)+2*x(3)+x(4)-1.8];
ceq = []
x0 = [0,0,0,0]
lb = [0.2,0.2,0.2,0.2]
ub = []
options = optimset('largescale' ,'off');
[x,fval] = fmincon('objfun',x0,[],[],[],[],lb,ub,'confun',options)
[c,ceq] = confun(x)
为什么没法运行,出现如下错误
>> confun
Error using confun (line 2)
Not enough input arguments.
求MATLAB大神给指出程序错误!function y = objfun(x)y = 1/x(1) + 2/x(2) + 4/x(3) + 6/x(4)function [c,ceq]=confun(x)c = [x(1)+x(2)+3*x(3)+3*x(4)-2;x(1)+2*x(2)+2*x(3)+x(4)-1.8];ceq = []x0 = [0,0,0,0]lb = [0.2,0.2,0.2,0.2]ub = []options = optimse
function y = objfun(x)
y = 1/x(1) + 2/x(2) + 4/x(3) + 6/x(4);
%这个程序独立保存为objfun.m
function [c,ceq]=confun(x)
c = [x(1)+x(2)+3*x(3)+3*x(4)-2;x(1)+2*x(2)+2*x(3)+x(4)-1.8];
ceq = [];
%这个程序独立保存为objfun.m;
clc
clear
x0 = [0,0,0,0]
lb = [0.2,0.2,0.2,0.2]
ub = []
options = optimset('largescale' , 'off','Algorithm','active-set');%Algorithm = 'active-set'
[x,fval] = fmincon('objfun',x0,[],[],[],[],lb,ub,'confun',options)
[c,ceq] = confun(x)
%这个程序独立保存为myfmin.m;运行本主程序就得到下面结果
运行结果
x0 =
0 0 0 0
lb =
0.2000 0.2000 0.2000 0.2000
ub =
[]
Local minimum possible. Constraints satisfied.
fmincon stopped because the predicted change in the objective function
is less than 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 1
x =
0.2000 0.2791 0.2279 0.2791
fval =
51.2177
c =
0
-0.3070
ceq =
[]