Demo entry 6769731

daima

   

Submitted by s on Nov 07, 2018 at 15:56
Language: Matlab. Code size: 4.4 kB.

clear;
clc;
stoptime=2000; T=0.01;         %初始条件
g11=0.74;g12=0.85;g21=0.74;g22=0.85;
xi11=0;xi12=0;xi21=0;xi22=0;
alpha11=0.2;alpha12=0.6;alpha21=0.2;alpha22=0.6;
l11=3;l12=0.8;l21=3;l22=0.8;

 for k=1:1:stoptime
%%%%%%%%%%%%%%%%%%%%%%%%%参考信号%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
   yd1(k)=0.5+0.3*cos(T*k*pi/6)+0.3*cos(T*k*pi/4);
   yd1(k+1)=0.5+0.3*cos(T*(k+1)*pi/6)+0.3*cos(T*(k+1)*pi/4);
   yd1(k+2)=0.5+0.3*cos(T*(k+2)*pi/6)+0.3*cos(T*(k+2)*pi/4); 
   yd2(k)=0.5+0.3*sin(T*k*pi/6)+0.3*sin(T*k*pi/4);
   yd2(k+1)=0.5+0.3*sin(T*(k+1)*pi/6)+0.3*sin(T*(k+1)*pi/4);
   yd2(k+2)=0.5+0.3*sin(T*(k+2)*pi/6)+0.3*sin(T*(k+2)*pi/4);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%跟踪误差%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
   e11(k)=xi11(k)-yd1(k);
   e21(k)=xi21(k)-yd2(k);
   if k==1
       e12(k)=xi12(k);
   else 
       e12(k)=xi12(k)-xi1(k-1);
   end
   if k==1
       e22(k)=xi22(k);
   else 
       e22(k)=xi22(k)-xi2(k-1);
   end
   %%%%%%%%%神经网络%%%%%%%%%%%%%%%% 
   %%%%%%%%虚拟控制%%%%%%%%%%%%%%%%%%%
   if k==1
       for i=1:12
           omega11(i,k)=0.1;
       end
   end
    for i=1:12
        s11(i)=exp(-((0.5*xi11(k)-0.2+0.5*i)^2+(xi12(k)-2+0.2*i)^2+(yd1(k+2)-4+0.2*i)^2)/5);  %激活函数
        if k==1
            omega11(i,k)=0.1-5*alpha11*s11(i)*(s11(i)*0.1+l11*e11(k));
        else
           omega11(i,k)=omega11(i,k-1)-3*alpha11*s11(i)*(s11(i)*omega11(i,k-1)+l11*e11(k));
        end
    end
    xi1(k)=omega11(:,k)'*s11';
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
    if k==1
       for i=1:12
           omega21(i,k)=0.1;
       end
   end
    for i=1:12
        s21(i)=exp(-((0.5*xi21(k)-0.2+0.5*i)^2+(xi22(k)-2+0.2*i)^2+(yd2(k+2)-4+0.2*i)^2)/5);  %激活函数
        if k==1
             omega21(i,k)=0.1-5*alpha21*s21(i)*(s21(i)*0.1+l21*e21(k));
        else
             omega21(i,k)=omega21(i,k-1)-3*alpha21*s21(i)*(s21(i)*omega21(i,k-1)+l21*e21(k));
        end
    end
    xi2(k)=omega21(:,k)'*s21';
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%控制器%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
   if k==1
       for i=1:20 
           omega12(i,k)=0.1;
       end
   end
    for i=1:20
        s12(i)=exp(-((0.5*xi11(k)-0.2+0.5*i)^2+(xi12(k)-2+0.2*i)^2+(xi1(k)-4+0.2*i)^2)/5); %激活函数
       if k==1
           omega12(i,k)=0.1-5*alpha12*s12(i)*(s12(i)*0.1+l12*e12(k));
       else
           omega12(i,k)=omega12(i,k-1)-3*alpha12*s12(i)*(s12(i)*omega12(i,k-1)+l12*e12(k));
       end
    end
    u1(k)=omega12(:,k)'*s12';
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    if k==1
       for i=1:30
           omega22(i,k)=0.1;
       end
   end
    for i=1:30
        s22(i)=exp(-((0.5*xi21(k)-0.2+0.5*i)^2+(xi22(k)-2+0.2*i)^2+(xi2(k)-4+0.2*i)^2)/5);  %激活函数
        if k==1
            omega22(i,k)=0.1-3*alpha22*s22(i)*(s22(i)*0.1+l22*e22(k));
        else
            omega22(i,k)=omega22(i,k-1)-5*alpha22*s22(i)*(s22(i)*omega22(i,k-1)+l22*e22(k));
        end
    end
    u2(k)=omega22(:,k)'*s22';
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%系统方程%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    f11(k)=xi11(k)^2/(1+2*xi12(k)^2+3*xi21(k)^2+4*xi22(k)^2);
    f12(k)=xi12(k)^2/(1+xi12(k)^2+xi21(k)^2+xi22(k)^2);
    d1(k)=0.04*cos(0.05*k)*cos(0.2*xi11(k));
    f21(k)=xi21(k)^2/(1+2*xi12(k)^2+3*xi21(k)^2+4*xi22(k)^2);
    f22(k)=xi22(k)^2/(1+xi12(k)^2+xi21(k)^2+xi22(k)^2)*u1(k)^2;
    d2(k)=0.04*cos(0.05*k)*cos(0.2*xi21(k));
    xi11(k+1)=f11(k)+g11*xi12(k);
    xi12(k+1)=f12(k)+g12*u1(k)+d1(k);
    xi21(k+1)=f21(k)+g21*xi22(k);
    xi22(k+1)=f22(k)+g22*u2(k)+d2(k);
    y1(k)=xi11(k);
    y2(k)=xi21(k);
    e11(k+1)=xi11(k+1)-yd1(k+1);
 if k<=stoptime
    y11(k)=y1(k);
    yd11(k)=yd1(k);
    y21(k)=y2(k);
    yd21(k)=yd2(k);
    u11(k)=u1(k);
    u22(k)=u2(k);
    e12(k)=e12(k);
    e22(k)=e22(k);
%     omega1(k)=norm(omega11(:,k));
%     omega2(k)=norm(omega12(:,k));
%     omega3(k)=norm(omega21(:,k));
%     omega4(k)=norm(omega22(:,k));
%     Rho1(k)=rho1(k);
%     Rho2(k)=rho2(k);
end
end
k=1:1:stoptime;
plot(k,y11,'-r',k,yd11,'--b');xlabel('Time(sec)');
figure
plot(k,y21,'-r',k,yd21,'--b');xlabel('Time(sec)');
figure,
plot(k,u1,'-r',k,u2,'-b');xlabel('Time(sec)');
figure,
plot(k,e12,'-r',k,e22,'-b');xlabel('Time(sec)');

This snippet took 0.02 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).