Training Neural Networks with MATLAB to Predict Nonlinear System Outputs

First, input a sine signal into the nonlinear system to obtain a set of input-output data, train a neural network, and then use this neural network to predict the output of the nonlinear system.

%shenjingwangluoxunlian

close all

clear ;

y_1=0;

y_2=0;

z_1=0;

z_2=0;

t1=0:0.05:50;

u1=10*sin(2*pi*5*t1);

Len=length(u1);

yy1=zeros(1,Len);

for k1=1:Len

z_0=u1(k1);

y_0=0.2*y_1/(1.5+0.1*y_1*y_1)-0.4*y_2-0.8*z_1+0.6*z_1*z_2;

yy1(k1)=y_0;

y_2=y_1;

y_1=y_0;

z_2=z_1;

z_1=z_0;

end

save u1_yy1.mat u1 yy1;

figure(1);

plot( t1,u1,’b’,t1,yy1,’r’);

%%%%%%%%%%%%%%%%%%%

u1a=u1(1:600);

u1b=u1(601:Len);

yy1a=yy1(1:600);

yy1b=yy1(601:Len);

p1=[delaysig(u1a,1,6);

delaysig(yy1a,1,6)];

net1=feedforwardnet(20, ‘trainlm’);

net1=train(net1, p1, yy1a);

p2=[delaysig(u1b,1,6);

delaysig(yy1b,1,6)];

p2(:,1:6)=[];

yy2=net1(p2);

figure(2)

plot(t1(607:Len),yy1(607:Len),’b’,t1(607:Len),yy2,’r’);

%%lianghao jieguo

figure(3);

plot(t1(607:Len),yy2-yy1(607:Len),’b’);

%%%%%%%%%%%%%%%%%%%%%%

u1=5*sin(2*pi*3*t1) ;%%5*cos(2*pi*3*t1) ;

z_1=0;

z_2=0;

y_1=0;

y_2=0;

for k1=1:Len

z_0=u1(k1);

y_0=0.2*y_1/(1.5+0.1*y_1*y_1)-0.4*y_2-0.8*z_1+0.6*z_1*z_2;

yy1(k1)=y_0;

y_2=y_1;

y_1=y_0;

z_2=z_1;

z_1=z_0;

end

p3=[delaysig(u1,1,6);

delaysig(yy1,1,6)];

yy4=net1(p3);

%%bulianghao jieguo

figure(4);

plot(t1,yy4-yy1,’b’);

Leave a Comment