✅作者简介:热爱科研的Matlab仿真开发者,修心和技术同步精进,matlab项目合作可私信。
🍎个人主页:Matlab科研工作室
🍊个人信条:格物致知。
更多Matlab仿真内容点击👇
⛄ 内容介绍
基于人工神经网络(Artificial Neural Network, ANN)进行非线性系统识别是一种常见的方法。ANN通过模拟人脑神经元之间的连接和信息传递过程,能够学习和建模非线性系统的输入输出关系。下面将介绍基于ANN进行非线性系统识别的基本原理和步骤。
-
数据准备:收集非线性系统的输入和输出数据,并进行预处理,如归一化或标准化处理,以提高网络训练的效果和准确性。
-
网络结构设计:选择合适的ANN结构,包括输入层、隐藏层和输出层的节点数、层数以及激活函数的选择。网络结构的设计应根据具体问题和数据特点进行调整。
-
数据划分:将数据集划分为训练集、验证集和测试集。训练集用于网络参数的训练,验证集用于调整网络结构和防止过拟合,测试集用于评估网络的性能。
-
网络训练:使用训练集数据对ANN进行训练,通过反向传播算法或其他优化算法来更新网络参数,使得网络的输出逼近实际输出。
-
网络验证和调整:使用验证集数据评估网络的性能,并根据验证结果进行网络结构的调整,如调整隐藏层节点数、增加正则化项等,以提高网络的泛化能力。
-
网络测试:使用测试集数据对训练好的ANN进行性能评估,验证其在未知数据上的准确性和鲁棒性。
-
结果分析:分析网络输出与实际输出之间的差异,评估网络的识别精度和预测能力,并根据需要进行进一步优化或改进。
需要注意的是,ANN的训练过程是一个迭代优化的过程,可能需要多次调整网络参数和结构,并进行多轮训练才能得到较好的结果。此外,对于复杂的非线性系统,可能需要更深层次、更复杂的ANN结构来提高识别性能。
⛄ 部分代码
clear; clc; close all;
%Input
%--------------------------------------------------------------------------
%Nodes Coordinates and Degrees of Freedoms
%------------------------------------------
Node{1}.x=0; Node{1}.y=0; %Node Coordinates
Node{2}.x=5; Node{2}.y=0;
Node{3}.x=5; Node{3}.y=5;
Node{4}.x=0; Node{4}.y=5;
Node{1}.DOFx=1; Node{1}.DOFy=2; Node{1}.DOFtheta=3; %Indices for x, y, and Rotation Degree of Freedoms.
Node{2}.DOFx=4; Node{2}.DOFy=5; Node{2}.DOFtheta=6;
Node{3}.DOFx=7; Node{3}.DOFy=8; Node{3}.DOFtheta=9;
Node{4}.DOFx=10; Node{4}.DOFy=11; Node{4}.DOFtheta=12;
%Material
%-----------------
Material{1}.E=200e9; %Modulus of Elasticity
Material{1}.f_y=400e6; %Stress Beyond Which the Stiffness Decreases
Material{1}.Ep=2e9; %Reduced Modulus of Elasticity
Material{1}.rho=7800; %Material Density
%Elements Nodes Connectivity, Area, Moment of Inertia, Modulus of Elasticity, Density, and Rayleigh Damping Parameters
%---------------------------------------------------------------------------------------------------------------------
Element{1}.Nodes=[1 4]; %Element Nodes Connectivity
Element{1}.Material=1; %Element Material
Element{1}.alpha=0.001; %Element Rayleigh Damping Parameter alpha
Element{1}.beta=0.001; %Element Rayleigh Damping Parameter beta
b1=0.1; h1=0.1;
for i=1:1:10
Element{1}.Section{i}.x=1/sqrt(3)*b1/2*[-1 -1 1 1]; %Element Section integation points x coordinates
Element{1}.Section{i}.y=1/sqrt(3)*h1/2*[-1 1 -1 1]; %Element Section integation points y coordinates
Element{1}.Section{i}.A=b1*h1/4*[1 1 1 1]; %Element Section integation points areas
Element{1}.Section{i}.e=[0 0 0 0]; %Element Section integation points initial stresses
Element{1}.Section{i}.s=[0 0 0 0]; %Element Section integation points initial strains
Element{1}.Section{i}.k=[0 0 0 0]; %Element Section integation points initial hardening
end
Element{2}.Nodes=[3 2];
Element{2}.Material=1;
Element{2}.alpha=0;
Element{2}.beta=0.00001;
b2=0.1; h2=0.1;
for i=1:1:10
Element{2}.Section{i}.x=1/sqrt(3)*b2/2*[-1 -1 1 1];
Element{2}.Section{i}.y=1/sqrt(3)*h2/2*[-1 1 -1 1];
Element{2}.Section{i}.A=b2*h2/4*[1 1 1 1];
Element{2}.Section{i}.e=[0 0 0 0];
Element{2}.Section{i}.s=[0 0 0 0];
Element{2}.Section{i}.k=[0 0 0 0];
end
Element{3}.Nodes=[4 3];
Element{3}.Material=1;
Element{3}.alpha=0;
Element{3}.beta=0.00001;
b3=0.1; h3=0.1;
for i=1:1:10
Element{3}.Section{i}.x=1/sqrt(3)*b3/2*[-1 -1 1 1];
Element{3}.Section{i}.y=1/sqrt(3)*h3/2*[-1 1 -1 1];
Element{3}.Section{i}.A=b3*h3/4*[1 1 1 1];
Element{3}.Section{i}.e=[0 0 0 0];
Element{3}.Section{i}.s=[0 0 0 0];
Element{3}.Section{i}.k=[0 0 0 0];
end
%Support, Support Displacement, and Applied Force
%-------------------------------------------------
steps=1000; %Number of Analysis Steps
Support=[1 2 3 4 5 6]; %Indices of Degrees of Freedom of Supports
NSupport=length(Support);
U_s=zeros(NSupport,steps); %Support Displacement Matrix of Size (Number of Supports, Number of Analysis Steps)
dU_s=zeros(NSupport,steps); %Support Velocity Matrix of Size (Number of Supports, Number of Analysis Steps)
ddU_s=zeros(NSupport,steps); %Support Acceleration Matrix of Size (Number of Supports, Number of Analysis Steps)
NNode=length(Node);
Force=zeros(3*NNode,steps); %Force Matrix of Size (Number of Degrees of Freedoms=3*Number of Nodes, Number of Analysis Steps)
Force(10,:)=600.*[1:steps].*sin(1*[1:steps]/10);
fs=300; %Sampling Frequency
delta=10e-4; %Convergance criterion for residual force
%Processing
%--------------------------------------------------------------------------
[Node,Element,F_s,Elements_N]=Analysis(Node,Element,Material,Support,U_s,dU_s,ddU_s,Force,fs,delta);
shear=zeros(steps,1);
for i=1:1:steps
shear(i)=Elements_N{i}{1}.f(1);
end
%Output
%--------------------------------------------------------------------------
Mag_Factor=1; %Magnification Factor for Plot
step=steps; %Step Number to be Plotted
Plot_Results(Node,Element,Mag_Factor,0,step); title(strcat('Deflected Shape @ Step=',num2str(step)));
Plot_Results(Node,Element,Mag_Factor,1,step); title(strcat('Axial Strain @ Step=',num2str(step)));
Plot_Results(Node,Element,Mag_Factor,2,step); title(strcat('Curvature @ Step=',num2str(step)));
Plot_Results(Node,Element,Mag_Factor,3,step); title(strcat('Axial Force @ Step=',num2str(step)));
Plot_Results(Node,Element,Mag_Factor,4,step); title(strcat('Moment @ Step=',num2str(step)));
t=[0:1:steps-1]/fs;
figure;
subplot(4,1,1);
plot(t,Force(10,:));
xlabel('Time (s)');
ylabel('Force (N)');
title('Horizontal Force, DISP, VEL, and ACC at Node 4');
subplot(4,1,2);
plot(t,Node{4}.Ux);
xlabel('Time (s)');
ylabel('DISP (m)');
subplot(4,1,3);
plot(t,Node{4}.dUx);
xlabel('Time (s)');
ylabel('VEL (m/s)');
subplot(4,1,4);
plot(t,Node{4}.ddUx);
xlabel('Time (s)');
ylabel('ACC (m/s^2)');
%Identification using neural network
%--------------------------------------------------------------------------
X=Force(10,:); %Input of neural network is forces
T=[Node{4}.Ux*100000 ; shear']; %Output of neural network is displacement and base shear
[X,~] = tonndata(X,1,0); %Change format of input data
[T,~] = tonndata(T,1,0); %Change format of output data
net = narxnet(0,4,4); %Create (nonlinear autoregressive with external input) network with 0 input delays and 4 output delays
[Xs,Xi,Ai,Ts] = preparets(net,X,{},T); %Prepares data for training
net = train(net,Xs,Ts,Xi,Ai); %Train the network
view(net) %View the network
Yopen = net(Xs,Xi,Ai); %Predict Output
net = closeloop(net); %convert to closed loop neural network
view(net); %view closed-loop network
[Xs,Xi,Ai,Ts] = preparets(net,X,{},T); %Prepares data for training
net = train(net,Xs,Ts,Xi,Ai); %Train the network
Yclosed = net(Xs,Xi,Ai); %Predict Output
%Plot output with predicted output
%--------------------------------------------------------------------------
T=cell2mat(T);
Yopen=cell2mat(Yopen);
Yclosed=cell2mat(Yclosed);
figure;
plot(t(5:end),T(1,5:end)/100000,'b-',t(5:end),Yopen(1,:)/100000,'r--',t(5:end),Yclosed(1,:)/100000,'k-.'); xlabel('Time (sec)'); ylabel('DISP (m)');
legend('Actual','Predicted (openloop)','Predicted (closedloop)');
figure;
plot(T(1,5:end)/100000,T(2,5:end),'b-',Yopen(1,:)/100000,Yopen(2,:),'r--',Yclosed(1,:)/100000,Yclosed(2,:),'k-.');
xlabel('Interstory Drift (m)');
ylabel('Interstory Shear (N)');
legend('Actual','Predicted (openloop)','Predicted (closedloop)');
⛄ 运行结果
⛄ 参考文献
[1] 曲东才.基于ANN逆模型的非线性系统辨识和控制仿真[C]//中国控制与决策学术年会.2006.DOI:ConferenceArticle/5aa2fa4cc095d72220ac9bd4.