智能控制第七单元书上源程序chap7-1.m%BPidentificationclearall;closeall;xite=0.50;alfa=0.05;w2=rands(6,1);w2_1=w2;w2_2=w2_1;w1=rands(2,6);w1_1=w1;w1_2=w1;dw1=0*w1;x=[0,0]';u_1=0;y_1=0;I=[0,0,0,0,0,0]';Iout=[0,0,0,0,0,0]';FI=[0,0,0,0,0,0]';ts=0.001;fork=1:1:1000time(k)=k*ts;u(k)=0.50*sin(3*2*pi*k*ts);y(k)=u_1^3+y_1/(1+y_1^2);forj=1:1:6I(j)=x'*w1(:,j);Iout(j)=1/(1+exp(-I(j)));endyn(k)=w2'*Iout;%OutputofNNInetworkse(k)=y(k)-yn(k);%Errorcalculationw2=w2_1+(xite*e(k))*Iout+alfa*(w2_1-w2_2);forj=1:1:6FI(j)=exp(-I(j))/(1+exp(-I(j)))^2;endfori=1:1:2forj=1:1:6dw1(i,j)=e(k)*xite*FI(j)*w2(j)*x(i);endendw1=w1_1+dw1+alfa*(w1_1-w1_2);%%%%%%%%%%%%%%Jacobian%%%%%%%%%%%%%%%%yu=0;forj=1:1:6yu=yu+w2(j)*w1(1,j)*FI(j);enddyu(k)=yu;x(1)=u(k);x(2)=y(k);w1_2=w1_1;w1_1=w1;w2_2=w2_1;w2_1=w2;u_1=u(k);y_1=y(k);endfigure(1);plot(time,y,'r',time,yn,'b');xlabel('times');ylabel('yandyn');figure(2);plot(time,y-yn,'r');xlabel('times');ylabel('error');figure(3);plot(time,dyu);xlabel('times');ylabel('dyu');chap7-2a.m%BPTrainingforMIMOandMulti-samplesclearall;closeall;xite=0.50;alfa=0.05;w2=rands(6,2);w2_1=w2;w2_2=w2_1;w1=rands(3,6);w1_1=w1;w1_2=w1;dw1=0*w1;I=[0,0,0,0,0,0]';Iout=[0,0,0,0,0,0]';FI=[0,0,0,0,0,0]';OUT=2;k=0;E=1.0;NS=3;whileE=1e-020k=k+1;times(k)=k;fors=1:1:NS%MIMOSamplesxs=[1,0,0;0,1,0;0,0,1];%IdealInputys=[1,0;0,0.5;0,1];%IdealOutputx=xs(s,:);forj=1:1:6I(j)=x*w1(:,j);Iout(j)=1/(1+exp(-I(j)));endyl=w2'*Iout;yl=yl';el=0;y=ys(s,:);forl=1:1:OUTel=el+0.5*(y(l)-yl(l))^2;%Outputerrorendes(s)=el;E=0;ifs==NSfors=1:1:NSE=E+es(s);endendey=y-yl;w2=w2_1+xite*Iout*ey+alfa*(w2_1-w2_2);forj=1:1:6S=1/(1+exp(-I(j)));FI(j)=S*(1-S);endfori=1:1:3forj=1:1:6dw1(i,j)=xite*FI(j)*x(i)*(ey(1)*w2(j,1)+ey(2)*w2(j,2));endendw1=w1_1+dw1+alfa*(w1_1-w1_2);w1_2=w1_1;w1_1=w1;w2_2=w2_1;w2_1=w2;end%EndofforEk(k)=E;end%Endofwhilefigure(1);plot(times,Ek,'r');xlabel('k');ylabel('E');savewfilew1w2;chap7-2b.m%TestBPclearall;loadwfilew1w2;%NSamplesx=[0.970,0.001,0.001;0.000,0.980,0.000;0.002,0.000,1.040;0.500,0.500,0.500;1.000,0.000,0.000;0.000,1.000,0.000;0.000,0.000,1.000];fori=1:1:7forj=1:1:6I(i,j)=x(i,:)*w1(:,j);Iout(i,j)=1/(1+exp(-I(i,j)));endendy=w2'*Iout';y=y'chap7-3.m%RBFidentificationclearall;closeall;alfa=0.05;xite=0.5;x=[0,0]';b=1.5*ones(4,1);c=0.5*ones(2,4);w=rands(4,1);w_1=w;w_2=w_1;c_1=c;c_2=c_1;b_1=b;b_2=b_1;d_w=0*w;d_b=0*b;y_1=0;ts=0.001;fork=1:1:2000time(k)=k*ts;u(k)=0.50*sin(1*2*pi*k*ts);y(k)=u(k)^3+y_1/(1+y_1^2);x(1)=u(k);x(2)=y_1;forj=1:1:4h(j)=exp(-norm(x-c(:,j))^2/(2*b(j)*b(j)));endym(k)=w'*h';em(k)=y(k)-ym(k);forj=1:1:4d_w(j)=xite*em(k)*h(j);d_b(j)=xite*em(k)*w(j)*h(j)*(b(j)^-3)*norm(x-c(:,j))^2;fori=1:1:2d_c(i,j)=xite*em(k)*w(j)*h(j)*(x(i)-c(i,j))*(b(j)^-2);endendw=w_1+d_w+alfa*(w_1-w_2);b=b_1+d_b+alfa*(b_1-b_2);c=c_1+d_c+alfa*(c_1-c_2);%%%%%%%%%%%%%%%%%%%Jacobian%%%%%%%%%%%%%%%%%%%%yu=0;forj=1:1:4yu=yu+w(j)*h(j)*(c(1,j)-x(1))/b(j)^2;enddyu(k)=yu;y_1=y(k);w_2=w_1;w_1=w;c_2=c_1;c_1=c;b_2=b_1;b_1=b;endfigure(1);plot(time,y,'r',time,ym,'b');xlabel('time(s)');ylabel('yandym');figure(2);plot(time,y-ym,'r');xlabel('time(s)');ylabel('identificationerror');figure(3);plot(time,dyu,'r');xlabel('times');ylabel('dyu');chap7-4.m%DiagonalRecurrentNeuralNetworkclearall;closeall;wd=rands(7,1);wo=rands(7,1);wi=rands(3,7);xj=zeros(7,1);xj_1=xj;u_1=0;y_1=0;xitei=0.35;xited=0.35;xiteo=0.35;ts=0.001;fork=1:1:1000time(k)=k*ts;u(k)=0.5*sin(4*pi*k*ts);y(k)=u_1^3+y_1/(1+y_1^2);Ini=[u_1,y_1,1]';forj=1:1:7sj(j)=Ini'*wi(:,j)+wd(j)*xj(j);endforj=1:1:7xj(j)=(1-exp(-sj(j)))/(1+exp(-sj(j)));endPj=0*xj;forj=1:1:7Pj(j)=wo(j)*(1+xj(j))*(1-xj(j))*xj_1(j);endQij=0*wi;forj=1:1:7fori=1:1:3Qij(i,j)=wo(j)*(1+xj(j))*(1-xj(j))*Ini(i);endendymk=0;forj=1:1:7ymk=ymk+xj(j)*wo(j);endym(k)=ymk;e(k)=y(k)-ym(k);wo=wo+xiteo*e(k)*xj;wd=wd+xited*e(k)*Pj;wi=wi+xitei*e(k)*Qij;xj_1=xj;u_1=u(k);y_1=y(k);endfigure(1);plot(time,y,'r',time,ym,'b');xlabel('time(s)');ylabel('Approaching');figure(2);plot(time,y-ym,'r');xlabel('time(s)');ylabel('Approachingerror');