使用 fmincon 优化但一直busy 的问题
当B1=2,B2=30,时运行到一半会停住,当改变B1 B2的值,如B1=2,B2=0.3,可以运行,不明白怎么回事,另外想尝试1stOpt解,不知道在1stOpt代码是怎么写的?求助,急啊 代码如下,也可以在上面附件里找到,帮忙看看 多谢了 另外会用1stOpt的同学可不可以告诉我相应的1stOpt,我用1stOpt解也出错~
clear all;
B1=2;
B2=30;
B3=0.75; %sin(angle a1 and a2)^2
B4=sqrt(1-B3); %cos(angle a1 and a2)
r1max=1/2*log(1+B1);
r2max=1/2*log(1+B2);
save p B1 B2 B3 B4
fun0='-x(3)';% objective function
Aeq=[];beq=[];A=[];b=[];
lb=;
ub=;
options=optimset('LargeScale','off');
r1=0:0.05:r1max
r2=0:0.05:r2max;
flag=0;
for i=1:length(r1)
if flag==1;
i=i-1;
break;
end
for j=1:length(r2)
assignin('base','r1s',r1(i));
assignin('base','r2s',r2(j));
x0=;% to set a better initial value
=fmincon(fun0,x0,A,b,Aeq,beq,lb,ub,@mycono,options);
if exitflag<1
mr0(i,j)=0;
end
if mr0(i,j)>0
mr0(i,j)=0
end
if mr0==0
j=j-1;
flag=1;% if the optimization can not handle or r0<0
break;
end
end
end
r0=-mr0;
=meshgrid(r1,r2);
meshz(r0);
ylabel('R1');xlabel('R2');zlabel('R0');
view();% set view angle
约束:
function =mycono(x) %nonlinear constraint
r1=evalin('base','r1s');
r2=evalin('base','r2s');
load p.mat
c=[-1/2*log(1+(1-x(1))*B1)+r1;
-1/2*log(1+(1-x(2))*B2)+r2;
-1/2*log(1+(1-x(1))*B1+(1-x(2))*B2+(1-x(1))*(1-x(2))*B1*B2*B3)+r1+r2;
-1/2*log(1+B1+B2+2*B4*sqrt(B1*B2*x(1)*x(2))+B1*B2*B3*(1-x(1)*x(2)))+r1+r2+x(3);
]
ceq=[];
end
[ 本帖最后由 eight 于 2007-12-14 09:34 编辑 ]
页:
[1]