急用!!matlab解决有约束的非线性优化

来源:百度知道 编辑:UC知道 时间:2024/05/11 04:42:51
我正在做一个毕业设计碰到在使用fmincon时程序出错!希望那位高手帮帮忙!问题描述如下
目标函数是:q=minx'px(其中x'是x的转置,p是一个4×4的矩阵,已知)
sub.to 1.635*x(3)^2+x(4)^2<=0.1174
我编了一个,但是总是出错误
M文件:
function f=myfuntest(x)
f=2.7845*x(1)*x(1)-1.0896*x(2)*x(2)+4.3216*x(3)*x(3)+0.1317*x(4)*x(4)+1.44*x(1)*x(2)-2.5852*x(1)*x(3)-0.158*x(1)*x(4)-1.5938*x(2)*x(3)-0.4084*x(2)*x(4)+0.6836*x(3)*x(4);
%fun函数
function [c,ceq]=myfuntestcon(x)
c=x(4)^2+(x(3)*x(3))*1.635-0.1179;
ceq=[];
%非线性约束
x0=[1;1;1;1];options=[];
>> x=fmincon(@myfuntest,x0,[],[],[],[],[],[],@myfuntestcon,options);
Warning: Large-scale (trust region) method does not currently solve this type of problem,
switching to medium-scale (line search).
> In C:\MATLAB6p5\toolbox\optim\fmincon.m at line 213
Maximum number of function evaluations exceeded;
increase OPTIONS.MaxFunEvals
对于其中的fun如下的改动:
function f=fmintest(x)
f=1.6979*x(1)*x(1)+1.9099*x(2)*x(2

再仔细检查每一个变量和句子吧,我发现好像没有最优解。

function hh
x0=[1 2 3 4];
options=optimset;
options.LargeScale='off'
options.MediumScale='on'
options.MaxFunEvals=1e30
options.MaxIter=1e7
x=fmincon(@myfuntest,x0,[],[],[],[],[],[],@myfuntestcon,options);
function f=myfuntest(x)
f=2.7845*x(1)*x(1)-1.0896*x(2)*x(2)+4.3216*x(3)*x(3)+0.1317*x(4)*x(4)+1.44*x(1)*x(2)-2.5852*x(1)*x(3)-0.158*x(1)*x(4)-1.5938*x(2)*x(3)-0.4084*x(2)*x(4)+0.6836*x(3)*x(4)
function [c,ceq]=myfuntestcon(x)
c=x(4)^2+(x(3)*x(3))*1.635-0.1174;
ceq=[];