|
楼主 |
发表于 2007-6-14 09:58
|
显示全部楼层
明天就要交了
前半部分是M文件 后面是函数调用文件
我的这个程序是遗传优化电机结构的。我也是照葫芦画瓢,从别的书上改的,帮我改一下
谢谢eight:handshake ,明天就要交了。
function f1=f(x);
a=58262.4./(x(:,4).*x(:,3).*x(:,1).*(0.08+0.79.*x(:,2)));
b=1+1.33.*a./1000;
c=(1.59/100000000).*x(:,2)./(x(:,2)+0.1).*x(:,3).^2.*x(:,1).^2;
d=(5.62/1000000000000.*x(3)^3.*x(:,1).^2.*x(:,4))./b;
e=0.55/100000000.*x(:,1).^2.*x(:,3).^3.*(1./(x(:,2)+0.1));
p=(2.79/100000000).*(x(:,2)./(x(:,2)+0.1)).*(x(:,3).^3.*x(:,1).^2./x(:,6));
g=7.69/1000000000000.*x(:,3).^3.*x(:,1).^2.*x(:,4)./b;
h=0.25/100000000.*((x(:,3).^3.*x(:,1).^2)./x(:,2)+0.1);
i=9.25.*(141.92+a)./(x(:,3).*x(:,1));
j=c+d+e;
k=p+g+h;
l=j+k;
m=(1+i.*j).*l.*1.1261^2.*(1+((1+i.*j).*l.*1.1261).^2);
n=(m+i).^2;
f1=-1/sqrt(1.2161^2+n);
function f2=f(x);
a1=58262.4./(x(:,4).*x(:,3).*x(:,1).*(0.08+0.79.*x(:,2)));
b1=1+1.33.*a1./1000;
c1=(1.59/100000000).*(x(:,2)./(x(:,2)+0.1)).*x(:,3).^2.*x(:,1).^2;
d1=(5.62/1000000000000.*x(3).^3.*x(:,1).^2.*x(:,4))./b1;
e1=0.55/100000000.*x(:,1).^2.*x(:,3).^3.*(1./(x(:,2)+0.1));
p1=(2.79/100000000).*(x(:,2)./(x(:,2)+0.1)).*(x(:,3).^3.*x(:,1).^2./x(:,6));
g1=7.69/1000000000000.*x(:,3).^3.*x(:,1).^2.*x(:,4)./b1;
h1=0.25/100000000.*((x(:,3).^3.*x(:,1).^2)./x(:,2)+0.1);
i1=9.25.*(141.92+a1)./(x(:,3).*x(:,1));
j1=c1+d1+e1;
k1=p1+g1+h1;
l1=j1+k1;
m1=(1+i1*j1).*l1.*1.1261^2.*(1+((1+i1.*j1).*l1.*1.1261).^2);
n1=(m1+i1).^2;
p1=sqrt(1.2161^2+n1);
f2=(p1.^2.*x(:,3).*x(:,1))/(16.67.*2.*x(:,4));
>>NIND=100;
>>MAXGEN=50;
>>NVAR=6;
>>PRECI=20;
>>GGAP=0.9;
>>trace1=[];trace2=[];trace3=[];
>>FieldD=[rep([PRECI],[1,NVAR]);[20,10,30,10,10,20;40,20,50,30,30,40];rep([1;0;1;1],[1,NVAR])];
>>Chrom=CRTBP(NIND,NVAR*PRECI);
>>v=BS2RV(Chrom,FieldD);
>>gen=1;
>>while gen<MAXGEN,
[NIND,N]=size(Chrom);
M=fix(NIND/2);
objV1=f1(v(1:M,:));
FitnV1=RANKING(objV1);
SelCh1=SELECT('sus',Chrom(1:M,:),FitnV1,GGAP);
ObjV2=f2(v(M+1:NIND,:));
FitnV2=RANKING(ObjV2);
SelCh2=SELECT('sus',Chrom((M+1):NIND,:),FitnV2,GGAP);
SelCh=[SelCh1;SelCh2];
SelCh=RECOMBIN('xovsp',SelCh,0.7);
Chrom=MUT(SelCh);
v=BS2RV(Chrom,FieldD);
trace1(gen,1)=min(f1(v));
trace1(gen,2)=sum(f1(v))/length(f1(v));
trace2(gen,1)=min(f2(v));
trace2(gen,2)=sum(f2(v))/length(f2(v));
trace3(gen,1)=min(f1(v)+f2(v));
trace3(gen,2)=sum(f1(v))/length(f1(v))+sum(f2(v))/length(f2(v));
gen=gen+1;
end
??? Error using ==> SELECT
Chrom and FitnV disagree
[ 本帖最后由 eight 于 2007-6-14 10:28 编辑 ] |
|