作业帮 > 综合 > 作业

这个程序哪里出问题了,该怎么修改?

来源:学生作业帮 编辑:作业帮 分类:综合作业 时间:2024/11/09 05:19:59
这个程序哪里出问题了,该怎么修改?
目标函数:
function f=myfun(x)
f=2.5*x(1)+0.25*x(2)+0.012*x(2)*x(3)+10;
约束文件:
function[c,ceq]=mycon(x)
c(1)=(1.82*10^5)/(x(3)^2)-225;
c(2)=[((0.008*x(1)+1)*1.5*(10^5))/0.89*x(1)^2]-150;
c(3)=((1.61*1e6)/(x(1)^2))-[(0.008*x(1)+1)*8.33*10^5/(0.89*(x(1)^2))]-150;
c(4)=0.5*(1.82*10^5)/(x(3)^2)+0.5*[(0.008*x(1)+1)*1.5*(10^5)/(0.89*x(1)^2)]-150;
c(5)=0.5*(1.82*10^5)/(x(3)^2)+0.5*[(1.61*(1e6)/(x(1)^2))-[(0.008*x(1)+1)*8.33*(10^5)/(0.89*x(1)^2)]-150;
ceq=[ ];
优化命令:
x0=[50,40,30];
options=optimset('display','iter','largescale','off')
[x,fval,exitflag,output]=fmincon(@myfun,x0,[],[],[],[],[],[],@mycon,options)
错误提示:
Error:File:C:\Documents and Settings\Administrator\桌面\a\mycon.m Line:7 Column:4
Assignment statements do not produce results.(Use == to test
for equality.)
Error in ==> C:\Documents and Settings\Administrator\桌面\a\Untitled3.m
On line 3 ==> [x,fval,exitflag,output]=fmincon(@myfun,x0,[],[],[],[],[],[],@mycon,options)
>>
把约束条件里的方括号 改为圆括号!
function [c,ceq]=mycon(x)
c(1)=(1.82*10^5)/(x(3)^2)-225;
c(2)=(((0.008*x(1)+1)*1.5*(10^5))/0.89*x(1)^2)-150;
c(3)=((1.61*1e6)/(x(1)^2))-[(0.008*x(1)+1)*8.33*10^5/(0.89*(x(1)^2))]-150;
c(4)=0.5*(1.82*10^5)/(x(3)^2)+0.5*((0.008*x(1)+1)*1.5*(10^5)/(0.89*x(1)^2))-150;
c(5)=0.5*(1.82*10^5)/(x(3)^2)+0.5*((1.61*(1e6)/(x(1)^2))-((0.008*x(1)+1)*8.33*(10^5)/(0.89*x(1)^2))-150);
ceq=[ ];



结果:

x =
1.0e+04 *
0.0007 0.0040 2.5301
fval =
1.2183e+04
exitflag =
0
output =
iterations: 75
funcCount: 303
lssteplength: 2
stepsize: 0.1082
algorithm: 'medium-scale: SQP, Quasi-Newton, line-search'
firstorderopt: 303.8591
constrviolation: 1.0010e+07
message: [1x142 char]