clear all %清除内存
tic    %秒表开始计时
A=[1 0.9 0.15 0.02];
B=[0 0.7 1.5];
C=[1 1.0 0.41];
X=[1 0.01 0.3];
th0=poly2th(A,B,1,C,1);
%随机产生粒子群的位置和速度,粒子数Xi为30
N=30;
S=50;
Xi=2.*rand(N,9);%均匀分布的随机数矩阵
Xpbest=zeros(N,9);%零矩阵
%Xnbest=zeros(N,9);
Vd=ones(N,9);%全1矩阵
Vdmax=ones(N,9);
C1=2;C2=2;
%评价每个粒子在Xi的适应度
u=idinput(S,'rs',[0 1],[-1,1]);
XO=u+0.01.*u.^2+0.3.*u.^3;
e=idinput(S,'rs',[0 1],[-0.1,0.1]);
y0=idsim([XO,e],th0);
pbest=zeros(N,1);
nbest=0;
xunhuan=1500; 
eemax=50;eemin=0;
w=0.9;
for num=1:xunhuan
   
   for i=1:N
     a=[1,Xi(i,1:3)];
     b=[0,Xi(i,4:5)];
     c=[1,Xi(i,6:7)];
     th1=poly2th(a,b,1,c,1);
     xo=u+Xi(i,8).*u.^2+Xi(i,9).*u.^3;
     y1=idsim([xo,e],th1);
    
     fitness(i)=1/(1+sum((y0-y1)'*(y0-y1)));
     %fitness(i)=(sum((y0-y1)'*(y0-y1)));
     %fitness(i)=1/ff;
     %比较fitness和pbest
     if fitness(i)>pbest(i)
        pbest(i)=fitness(i);
        Xpbest(i,:)=Xi(i,:);
     end
   end
   ee=sum((y0-y1)'*(y0-y1));
   if ee>eemax
      ee=eemax;
   end
   ee1=(ee-eemin)/(eemax-eemin);
   switch 1
     case and(and(w>=0.4,w<0.6),ee1<0.35)% w,ee1=s,s
          w=0.4;
     case and(and(w>=0.4,w<0.6),ee1<0.7)% w,ee1=s,m
          w=w+0.08; 
     case and(and(w>=0.4,w<0.6),ee1>=0.7)% w,ee1=s,l
          w=w+0.15; 
     case and(and(w>=0.6,w<0.75),ee1<0.35)% w,ee1=m,s
           w=w-0.05;
     case and(and(w>=0.6,w<0.75),ee1<0.7)% w,ee1=m,m
          w=w; 
     case and(and(w>=0.6,w<0.75),ee1>=0.7)% w,ee1=m,l
          w=w+0.10;
     case and(w>=0.75,ee1<0.35)% w,ee1=l,s
           w=w-0.10;
     case and(w>=0.75,ee1<0.7)% w,ee1=l,m
          w=w-0.08; 
     case and(w>=0.75,ee1>=0.7)% w,ee1=l,l
          w=+0.05; 
          
      end
      if w>0.9
         w=0.9
      end
      if w<0.4
         w=0.4
      end
   %比较nmf和nbest
   [nmf,n]=max(fitness);
   if nmf>nbest
      nbest=nmf;
      Xnbest=Xi(n,:);
   end
   %改变每一个粒子的速度和位置
   for i=1:N
      rand1=rand(1,1);
      rand2=rand(1,1);
      Vd(i,:)=w*Vd(i,:)+C1*rand1*(Xpbest(i,:)-Xi(i,:))+C2*rand2*(Xnbest-Xi(i,:));

      if Vd(i)>Vdmax(i)
         Vd(i)=Vdmax(i);
      elseif Vd(i)<-Vdmax(i)
         Vd(i)=-Vdmax(i);
      end
      Xi(i,:)=Xi(i,:)+Vd(i,:);
   end
end
a1=Xnbest(1)
a2=Xnbest(2)
a3=Xnbest(3)
b1=Xnbest(4)
b2=Xnbest(5)
c1=Xnbest(6)
c2=Xnbest(7)
r2=Xnbest(8)
r3=Xnbest(9)
time=toc
weight =w
error=ee
error1=ee1

 
 这个程序前几句是什么意思啊??麻烦说明下~