|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?我要加入
x
本帖最后由 牛小贱 于 2014-3-10 21:32 编辑
我这个程序是刘金琨老师那本书上抄下来的,但是我运行的时候有错,是神经网络调整PID的程序,哪位好心的朋友帮我看看到底错在哪里?程序如下:- clear all;
- close all;
- xite=0.25;
- alfa=0.05;
- belte=0.01;
- x=[0,0,0]';
- ci=30*ones(3,6);
- bi=40*ones(6,1)';
- w=10*ones(6,1);
- h=[0,0,0,0,0,0,0]';
- ci_1=ci;ci_2=ci_1;ci_3=ci_2;
- bi_1=bi;bi_2=bi_1;bi_3=bi_2;
- w_1=w;w_2=w_1;w_3=w_2;
- u_1=0;y_1=0;
- xc=[0,0,0]';
- e_1=0;e_2=0;e=0;
- kp0=0.03;
- ki0=0.01;
- kd0=0.03;
- kp_1=kp0;
- ki_1=ki0;
- kd_1=kd0;
- xitekp=0.2;
- xiteki=0.2;
- xitekd=0.2;
- ts=0.001;
- for k=1:1:2000
- time(k)=k*ts;
- r(k)=1.0*sign(sin(2*pi*k*ts));
- y(k)=(-0.1*y_1+u_1)/(1+y_1^2);
- for j=1:1:6
- h(j)=exp(-norm(x-ci(:,j))^2/(2*bi(j)^2));
- end
- ym(k)=w'*h;
-
- d_w=0*w;
- for j=1:1:6
- d_w(j)=xite*(y(k)-ym(k))*h(j);
- end
- w=w_1+d_w+alfa*(w_1-w_2)+belte*(w_2-w_3);
-
- d_bi=0*bi;
- for j=1:1:6
- d_bi(j)=xite*(y(k)-ym(k))*w(j)*h(j)/(bi(j)^3)*norm(x-ci(:,j))^2;
- end
- bi=bi_1+d_bi+alfa*(bi_1-bi_2)+belte*(bi_2-bi_3);
-
- for j=1:1:6
- for i=1:1:3
- d_ci(i,j)=xite*(y(k)-ym(k))*w(j)*h(j)*(x(i)-ci(i,j))/(bi(j)^2);
- end
- end
- ci=ci_1+d_ci+alfa*(ci_1-ci_2)+belte*(ci_2-ci_3);
-
- yu=0;
- for j=1:1:6
- yu=yu+w(j)*h(j)*(-x(1)+ci(1,j))/bi(j)^2
- end
- dy(k)=yu;
-
- e(k)=r(k)-y(k);
- kp(k)=kp_1+xitekp*e(k)*dy(k)*xc(1);
- kd(k)=kd_1+xitekd*e(k)*dy(k)*xc(2);
- ki(k)=ki_1+xiteki*e(k)*dy(k)*xc(3);
- if kp(k)<0
- kp(k)=0;
- end
- if kd(k)<0
- kd(k)=0;
- end
- if ki(k)<0
- ki(k)=0;
- end
-
- M=1;
- switch M
- case 1
- case 2
- kp(k)=kp0;
- ki(k)=ki0;
- kd(k)=kd0;
- end
- du(k)=kp(k)*xc(1)+kd(k)*xc(2)+ki(k)*xc(3);
- u(k)=u_1+du(k);
-
- x(1)=du(k);
- x(2)=y(k);
- x(3)=y_1;
-
- u_1=u(k);
- y_1=y(k);
-
- ci_3=ci_2;
- ci_2=ci_1;
- ci_1=ci;
-
- bi_3=bi_2;
- bi_2=bi_1;
- bi_1=bi;
-
- w_3=w_2;
- w_2=w_1;
- w_1=w;
-
- xc(1)=e(k)-e_1;
- xc(2)=e(k)-2*e_1+e_2;
- xc(3)=e(k);
-
- e_2=e_1;
- e_1=e(k);
-
- kp_1=kp(k);
- kd_1=kd(k);
- ki_1=ki(k);
- end
- figure(1);
- plot(time,r,'b',time,y,'r');
- xlabel('time(s)');ylabel('r,y');
- figure(2);
- plot(time,y,'r',time,ym,'b');
- xlabel('time(s)');ylabel('y,ym');
- figure(3);
- plot(time,dy);
- xlabel('time(s)');ylabel('Jacobian Value');
- figure(4);
- subplot(311);
- plot(time,kp,'r');
- xlabel('time(s)');ylabel('kp');
- subplot(312);
- plot(time,ki,'r');
- xlabel('time(s)');ylabel('ki');
- subplot(313);
- plot(time,kd,'r');
- xlabel('time(s)');ylabel('kd');
复制代码
|
|