. .
智能控制作业
学生: 学 号: 专业班级:
7-2 采用BP网路、RBF网路、DRNN网路逼近线性对象
u(k?1)?0.9?y(k?1)y(k)?,分别进行matlab仿真。 21?y(k?1)(一)采用BP网络仿真
网络结构为2-6-1。采样时间1ms,输入信号u(k)?0.5sin(6??t),权值W1,W2的初值随机取值,??0.05,??0.05。
仿真m文件程序为: %BP simulation clear all; clear all;
xite=0.5; alfa=0.5;
w1=rands(2,6); % value of w1,initially by random w1_1=w1;w1_2=w1;
w2=rands(6,1); % value of w2,initially by random w2_1=w2;w2_2=w2_1;
dw1=0*w1;
x=[0,0]';
u_1=0; y_1=0;
I=[0,0,0,0,0,0]'; % input of yinhanceng cell Iout=[0,0,0,0,0,0]'; % output of yinhanceng cell FI=[0,0,0,0,0,0]';
ts=0.001;
for k=1:1:1000
time(k)=k*ts;
u(k)=0.5*sin(3*2*pi*k*ts);
页脚
. .
y(k)=(u_1-0.9*y_1)/(1+y_1^2);
for j=1:1:6
I(j)=x'*w1(:,j);
Iout(j)=1/(1+exp(-I(j))); end
yn(k)=w2'*Iout; %output of network e(k)=y(k)-yn(k); % error calculation
w2=w2_1+(xite*e(k))*Iout+alfa*(w2_1-w2_2); % rectify of w2
for j=1:1:6
FI(j)=exp(-I(j))/(1+exp(-I(j))^2); end
for i=1:1:2 for j=1:1:6
dw1(i,j)=e(k)*xite*FI(j)*w2(j)*x(i); % dw1 calculation end end
w1=w1_1+dw1+alfa*(w1_1-w1_2); % rectify of w1
% jacobian information yu=0;
for j=1:1:6
yu=yu+w2(j)*w1(1,j)*FI(j); end
dyu(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); end
figure(1);
plot(time,y,'r',time,yn,'b');
xlabel('times');ylabel('y and yn'); figure(2);
页脚
. .
plot(time,y-yn,'r');
xlabel('times');ylabel('error'); figure(3);
plot(time,dyu);
xlabel('times');ylabel('dyu');
运行结果为:
页脚