请大家看看这个MATLAB程序哪里出了错?如何改?我的程序如下:function f=objfun(x)f=pi*(4.14*x(1)+2.5)^2*x(2)*x(3)^2/4;function [c,ceq]=confun(x)c=[6.35*10^5-x(1)^2*x(2)*x(3)^2;13432.29*(4.69-0.63*ln(x(1)))-x(1)*x(2)*x(3)^2];ceq=[
来源:学生作业帮助网 编辑:作业帮 时间:2024/06/28 21:41:39
请大家看看这个MATLAB程序哪里出了错?如何改?我的程序如下:function f=objfun(x)f=pi*(4.14*x(1)+2.5)^2*x(2)*x(3)^2/4;function [c,ceq]=confun(x)c=[6.35*10^5-x(1)^2*x(2)*x(3)^2;13432.29*(4.69-0.63*ln(x(1)))-x(1)*x(2)*x(3)^2];ceq=[
请大家看看这个MATLAB程序哪里出了错?如何改?
我的程序如下:
function f=objfun(x)
f=pi*(4.14*x(1)+2.5)^2*x(2)*x(3)^2/4;
function [c,ceq]=confun(x)
c=[6.35*10^5-x(1)^2*x(2)*x(3)^2;13432.29*(4.69-0.63*ln(x(1)))-x(1)*x(2)*x(3)^2];
ceq=[];
A=[0 -1 5;0 1 -17];
b=[0;0];
lb=[17;10;2];
ub=[50;100;6];
x0=[17;87;5];
[x,fval]=fmincon(@objfun,x0,A,b,[],[],vlb,vub,@confun)
运行之后出现:
Attempt to execute SCRIPT fmincon as a function.
为什么?
请大家看看这个MATLAB程序哪里出了错?如何改?我的程序如下:function f=objfun(x)f=pi*(4.14*x(1)+2.5)^2*x(2)*x(3)^2/4;function [c,ceq]=confun(x)c=[6.35*10^5-x(1)^2*x(2)*x(3)^2;13432.29*(4.69-0.63*ln(x(1)))-x(1)*x(2)*x(3)^2];ceq=[
问题
1 objfun的;改为半角;
2matlab 不识别 confun中ln 改为log
3fmincon vlb vub没定义 改为lb ub
----------------------------
function f=objfun(x)
f=pi*(4.14*x(1)+2.5)^2*x(2)*x(3)^2/4;
--------------------------------------
function [c,ceq]=confun(x)
c=[6.35*10^5-x(1)^2*x(2)*x(3)^2;13432.29*(4.69-0.63*log(x(1)))-x(1)*x(2)*x(3)^2];
ceq=[];
-------------------------------------
上面两个函数存为.m文件
命令窗口输入
A=[0 -1 5;0 1 -17];
b=[0;0];
lb=[17;10;2];
ub=[50;100;6];
x0=[17;87;5];
[x,fval]=fmincon(@objfun,x0,A,b,[],[],lb,ub,@confun)
Warning: Trust-region-reflective algorithm does not solve this type of problem, using
active-set algorithm. You could also try the interior-point algorithm: set the
Algorithm option to 'interior-point' and rerun.
> In fmincon at 460
Local minimum possible. Constraints satisfied.
fmincon stopped because the size of the current search direction is less than
twice the default value of the step size 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
1 2
x =
17.000000000000000
86.941482536032794
5.138256344408354
fval =
9.575582120628687e+006