clear
clc
alpha=0.05;
eta=0.2;
ny=2;d=2;nu=3;
n=ny+nu-d+1;
m=6;
w1k1=randn(m,n);%6*4
w1k2=w1k1;
w2k1=randn(1,m);%1*6
w2k2=w2k1;
L=1000;
uk=zeros(nu,1);%2*1
yk=zeros(ny,1);%2*1
fork=1:L
time(k)=k;
u(k)=0.8*sin(0.01*pi*k);
y(k)=uk(2)^3+uk(3)^3+(0.8+yk(1)^3)/(1+yk(1)^2+yk(2)^4);
X=[yk;uk(d:nu)];
o=X;%4*1
net2=w1k1*X;% 6*1
o2=1./(1+exp(-net2));%6*1
ym(k)=w2k1*o2;
e(k)=y(k)-ym(k);
dw2=eta*e(k)*o2';%1*6 e(k)ÊÇÒ»¸öÊý£¬kָϱꡣ
w2=w2k1+dw2+alpha*(w2k1-w2k2);%1*6
dnet2=exp(-net2)./(1+exp(-net2)).^2;%6*1
dw1k1=eta*e(k)*w2k1'.*dnet2*o';
w1=w1k1+dw1k1+alpha*(w1k1-w1k2);
w1k2=w1k1;w1k1=w1;
w2k2=w2k1;w2k1=w2;
for i=nu:-1:2
uk(i)=uk(i-1);
end
uk(1)=u(k);
for i=ny:-1:2
yk(i)=yk(i-1);
end
yk(1)=y(k);
end
subplot(211)
plot(time,y,'r:',time,ym,'k');
xlabel('k'); ylabel('y(k)¡¢y_m(k)');
legend('y(k)','y_m(k)'); %axis([0 L -.4 1.6]);
subplot(212)
plot(time,y-ym,'k');
xlabel('k'); ylabel('e(k)'); axis([0 L -1 1]);
网友评论