• 大小: 1.42 KB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2024-10-27
  • 语言: Matlab
  • 标签: FNN  MATLAB  

资源简介

FNN MATLAB实现,基于BP神经网络 可以直接运行得到结果,非常方便

资源截图

代码片段和文件信息

%BP based pd Control
clear all;
close all;

xite=[0.200.250.023];
alfa=0.05;

S=1; %Signal type

IN=4;H=5;Out=3;  %NN Structure
if S==1  %Step Signal
wi= [ -0.7880   -0.1852    0.4191   -0.0793
   -0.4214   -0.7626    0.4626    0.5830
    0.0877    0.8388    0.6949   -0.6356
   -0.4303    0.2373   -0.0067   -0.4239
    0.1719    0.2994   -0.7105    0.9005];

%wi=rands(HIN);
wi_1=wi;wi_2=wi;wi_3=wi;
wo=[0.8683   -0.6168    0.0563    0.4828   -0.0361
   -0.2999    0.1067   -0.5205    1.2318   -0.2118
    1.2552    0.0644    0.1043   -0.3045   -0.1613];

%wo=rands(OutH);
wo_1=wo;wo_2=wo;wo_3=wo;
end

if S==2  %Sine Signal
wi=[ -0.2691   -0.3048    0.1191   -0.2289
   -0.2539   -0.1522   -0.3347   -0.3918
    0.0798    0.3173    0.3262   -0.1676
    0.3478   -0.2870    0.1556   -0.0796
    0.3070    0.4127    0.0464    0.2066];
%wi=0.50*rands(HIN);
wi_1=wi;wi_2=wi;wi_3=wi;
wo=[1.0438    0.5478    0.8682    0.1446    0.1537;
    0.1716    0.5811    1.1214    0.5067    0.7370;
    1.0063    0.7428    1.0534    0.7824    0.6494];
%wo=0.50*rands(OutH);
wo_1=wo;wo_2=wo;wo_3=wo;
end

x=[000];
u_1=0;u_2=0;u_3=0;u_4=0;u_5=0;
y_1=0;y_2=0;y_3=0;

Oh=zeros(H1);    %Output from NN middle layer
I=Oh;             %Input to NN middle layer
error_2=0;
error_1=0;

ts=0.001;
for k=1:1:6000
time(k)=k*ts;

if S==1
   rin(k)=1.0;
elseif S==2
   rin(k)=sin(1*2*pi*k*ts);
end

%Unlinear model
a(k)=1.2*(1-0.8*exp(-0.1*k));
yout(k)=a(k)*y_1/(1+y_1^2)+u_1;

error(k)=rin(k)-yout(k);

xi=[rin(k)yout(k)error(k)1];

x(1)=error(k)-error_1;
x(2)=error(k);
x(3)=error(k)-2*error_1+error_2;

epd=[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))); %Middle layer
end
K=wo*Oh;             %Output layer
for l=1:1:Out
    K(l)=exp(K(l))/(exp(K(l))+exp(-K(l)));        %Getting kpkikd
end
kp(k)=K(1);ki(k)=K(2);kd(k)=K(3);
Kpd=[kp(k)ki(k)kd(k)];

du(k)=Kpd*epd;
u(k)=u_1+du(k);
if u(k)>=10       % Restricting the output of controller
   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));

%Output layer
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)*epd(l)*dK(l);
end

for l=1:1:Out
   for i=1:1:H
       d_wo=xite(Out)*delta3(l)*Oh(i)+alfa*(wo_1-wo_2);
   end
end
    wo=wo_1+d_wo+alfa*(wo_1-wo_2);
%Hidden layer
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
for l=1:1:Out
d_wi=xite(Out)*delta2‘*xi;
wi=wi_1+d_wi+alfa*(wi_1-wi_2);
end
%Parameters Update
u_5=u_4;u_4=u_3;u_3=u_2;u_2=u_1;u_1=u(k);   
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
figure(1);
plot(timerin‘r‘timeyout‘b‘);
xlabel(‘time(s)‘);ylabel(‘rinyout‘);
figure(2);
plot(timeerror‘r‘)

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件       3320  2014-09-01 10:53  nn based bp control.m

----------- ---------  ---------- -----  ----

                 3320                    1


评论

共有 条评论