dty7611477 发表于 2009-8-23 09:21:31

fmincon优化求助

本帖最后由 messenger 于 2009-8-25 23:22 编辑

能不能具体的指点一下
function y=opt_fun(x)
%数值积分
y=quadl(@t,xia(x),shang(x));
%求积分上限
function th_x=shang(x)
s=-(x(3)+x(4));
th3=asin((x(3).^2-x(4).^2+s.^2)./(2*s.*x(3)));
g=-2*x(1).*(x(6)+x(3).*sin(th3));
h=-2*x(1).*(x(5)+x(3).*abs(cos(th3)));
k=x(3).^2+x(1).^2-2*x(3).*x(5).*abs(cos(th3))+2*x(3).*x(6).*sin(th3)+x(5).^2+x(6).^2-x(2).^2;
th_x=2*atan((sqrt(g.^2+h.^2-k.^2)+g)./(h-k));
end
%求积分下限
function th_6=xia(x)
s=-(x(3)+x(4)+0.006);
th3=asin((x(3).^2-x(4).^2+s.^2)./(2*s.*x(3)));
g=-2*x(1).*(x(6)+x(3).*sin(th3));
h=-2*x(1).*(x(5)+x(3).*abs(cos(th3)));
k=x(3).^2+x(1).^2-2*x(3).*x(5).*abs(cos(th3))+2*x(3).*x(6).*sin(th3)+x(5).^2+x(6).^2-x(2).^2;
th_6=2*atan((sqrt(g.^2+h.^2-k.^2)+g)./(h-k));
end
%被积函数
function T=t(th)
d=2*x(2).*(x(1).*sin(th)-x(6));
e=2*x(2).*(x(1).*cos(th)+x(5));
f=(x(1).*cos(th)+x(5)).^2+(x(1).*sin(th)-x(6)).^2+x(2).^2-x(3).^2;
th2=2*atan((sqrt(d.^2+e.^2-f.^2)+d)./(e-f));

a=2*x(3).*(x(6)-x(1).*sin(th));
b=-2*x(3).*(x(5)+x(1).*cos(th));
c=x(3).^2-x(2).^2+(-x(1).*sin(th)).^2+(x(5)+x(1).*cos(th)).^2;
th3=2*atan((sqrt(a.^2+b.^2-c.^2)+d)./(b-c));
th4=acos(-x(3).*cos(th3)./x(4));
%T是最终的被积函数,上面是th2,th3,th4关于th的函数,要对th积分
T=x(1).*cos(th)+(x(1).*sin(th3-th).*sin(th4).*cos(th)-x(1).*sin(th2-th).*sin(th3).*sin(th4))./(sin(th2-th3).*sin(th4));
end

end

///////////////////////////////////////////////////
%约束函数
function =constrain(x)
c1=;
c2=[];
//////////////////////////////
%利用工具箱中的函数fmincon优化,求最优的L1 L2 L3 L4 x y使T最小值
x0=;
= fmincon(@opt_fun,x0,[],[],[],[],[],[],@constrain)
///////////////////////////////////////
Warning: Trust-region-reflective method does not currently solve this type of
problem,
using active-set (line search) instead.
> In fmincon at 439
In fmin at 3
Warning: Maximum function count exceeded; singularity likely.
> In quadl at 104
In opt_fun2 at 4
In nlconst at 814
In fmincon at 720
In fmin at 3
谢谢
页: [1]
查看完整版本: fmincon优化求助