clear all;close all;
%%%%%%%%%%%%%%%%%%%%%系统参数赋初值%%%%%%%%%%%%%%%%%%%%%x
xite=0.01;%学习速率
alfa=0.15;%惯性系数
IN=4;H=5;Out=3;
%wi=0.50*rands(H,IN);%神经网络权值初始化
wi=[-0.6534 -0.2842 -0.3906 -0.7250;
-0.8085 -0.1476 -0.4470 -0.1870;
-1.0428 0.5876 -1.6474 -0.4955;
-0.2832 0.0095 -0.5620 -0.1779;
0.4151 0.3087 -0.2521 -0.4145];
wi_1=wi;
wi_2=wi;
wi_3=wi;
%wo=0.50*rands(Out,H);
wo=[0.7588 0.2628 0.5832 -0.1404 -0.1313;
-0.1134 0.2961 0.8364 0.2217 0.4520;
0.7213 0.4578 0.7684 0.4974 0.3644];
wo_1=wo;wo_2=wo;wo_3=wo;
x=[0,0,0];
u_1=0.0;u_2=0.0;u_3=0.0;u_4=0;u_5=0;%PID输出赋初值,为方便后面的离散化
y_1=0.0;y_2=0.0;y_3=0.0;y_4=0;y_5=0;%输出给0值
error_1=0;error_2=0;Oh=zeros(H,1);
I=Oh;
%隐含层输入赋初值
%%%%%%%%%%%%%%%%%%%%%%%%计算%%%%%%%%%%%%%%%%%%%%%%%%%%
ts=0.96;
for k=1:1:200
time(k)=k*ts;
rin(k)=1.0;
num=[1];%Unlinearmodel
den=[10 1];
sys=tf(num,den,'inputdelay',0.5);%传递函数G(s)离散化
dsys=c2d(sys,ts,'z');
[num,den]=tfdata(dsys,'v');
yout(k)=-den(2)*y_1+num(2)*u_2+num(1)*u_1;%输出y离散化
error(k)=rin(k)-yout(k);
xi=[error(k),error_1,error_2,1];%输入层给值
x(1)=error(k)-error_1;
x(2)=error(k);
x(3)=error(k)-2*error_1+error_2;
epid=[x(1);x(2);x(3)];
I=xi*wi';%隐含层节点输入
for j=1:1:H
Oh(j)=(exp(I(j))-exp(-I(j)))/(exp(I(j))+exp(-I(j)));
end%隐含层活化函数tanhx变成了欧拉形式
K=wo*Oh; %输出层节点输入
for l=1:1:Out
K(l)=exp(K(l))/(exp(K(l))+exp(-K(l))); %输出层活化函数变成了欧拉氏 求解
end
kp(k)=K(1);ki(k)=K(2);kd(k)=K(3);%得到kp,ki,kd参数值
Kpid=[kp(k),ki(k),kd(k)];
du(k)=Kpid*epid;%计算U(k)
u(k)=u_1+du(k);
if u(k)>=10%Restrictingtheoutputofcontroller
u(k)=10;
end
if u(k)<=-10
u(k)=-10;
end
%%%%%%%%%%%%%%%%%%%%%反向修正%%%%%%%%%%%%%%%%%%%%%%%%%%输出层
dyu(k)=sign((yout(k)-y_1)/(u(k)-u_1+0.0000001));
for j=1:1:Out
dK(j)=2/(exp(K(j))+exp(-K(j)))^2;
end
for l=1:1:Out
delta3(l)=error(k)*dyu(k)*epid(l)*dK(l);%dJ/dWo
end
for l=1:1:Out
for i=1:1:H
d_wo=xite*delta3(l)*Oh(i)+alfa*(wo_1-wo_2);
end
end
wo=wo_1+d_wo+alfa*(wo_1-wo_2);
%隐含层
for i=1:1:H
dO(i)=4/(exp(I(i))+exp(-I(i)))^2;
end
segma=delta3*wo;
for i=1:1:H
delta2(i)=dO(i)*segma(i);
end
d_wi=xite*delta2'*xi;
wi=wi_1+d_wi+alfa*(wi_1-wi_2);
%数据更新,循环修正
u_5=u_4;u_4=u_3;u_3=u_2;u_2=u_1;u_1=u(k);
y_5=y_4;y_4=y_3;y_3=y_2;y_2=y_1;y_1=yout(k);
wo_3=wo_2;
wo_2=wo_1;
wo_1=wo;
wi_3=wi_2;
wi_2=wi_1;
wi_1=wi;
error_2=error_1;error_1=error(k);
end
wi%找到较为合适的权值,缩小调整范围
wo
%%%%%%%%%%%%%%%%%%%%%%%%绘图%%%%%%%%%%%%%%%%%%%%%%%%%%%%
figure(1);
plot(time,rin,'r',time,yout,'b');
xlabel('time(s)');ylabel('rin,yout');%被控对象y
figure(2);
plot(time,error,'r');
xlabel('time(s)');ylabel('error');%误差
figure(3);
plot(time,u,'r');
xlabel('time(s)');ylabel('u');%pid输出u
figure(4);
subplot(311);
plot(time,kp,'r');
xlabel('time(s)');ylabel('kp');%kp,ki,kd值
subplot(312);
plot(time,ki,'g');
xlabel('time(s)');ylabel('ki');
subplot(313);
plot(time,kd,'b');
xlabel('time(s)');ylabel('kd');
BPPID.rar_BPPID_PID 参数整定_PID 整定_bppid效果好差_神经PID
版权申诉
162 浏览量
2022-07-15
19:50:28
上传
评论
收藏 2KB RAR 举报
![avatar](https://profile-avatar.csdnimg.cn/f3b7c8d80edb45ee84389e2d10b9d009_weixin_42662293.jpg!1)
局外狗
- 粉丝: 69
- 资源: 1万+
最新资源
- Docker技术:Docker安装与配置教程+运维技术+超融合+虚拟技术+云计算
- ZeRO Memory Optimizations Toward Training LLM.pdf
- 高效SQL语句编写(how-to-write-efficient-sql)
- ZeroTermux-release_sign.apk
- 非弹性斜碰撞物理课件模拟-HTML网页制作
- 软件测试学习日志-测试基础-day02
- 制作一个简单的进销存(库存管理)页面.rar
- Mixture-of-Experts with Expert Choice Routing.pdf
- Mixtral AI.pdf
- Learning Factored Representations in a Deep MOEs.pdf
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
![feedback](https://img-home.csdnimg.cn/images/20220527035711.png)
![feedback](https://img-home.csdnimg.cn/images/20220527035711.png)
![feedback-tip](https://img-home.csdnimg.cn/images/20220527035111.png)
评论0