刘金琨RBF_随书仿真

This commit is contained in:
iHoney725
2021-01-04 10:31:19 +08:00
committed by GitHub
parent 617d1261df
commit 661aff3b19
62 changed files with 4055 additions and 0 deletions
+88
View File
@@ -0,0 +1,88 @@
function [sys,x0,str,ts] = Book4341_Controller(t,x,u,flag)
% RBF神经网络的直接鲁棒自适应控制
switch flag
case 0
[sys,x0,str,ts]=mdlInitializeSizes;
case 1
sys=mdlDerivatives(t,x,u);
case {2,4,9}
sys=[];
case 3
sys=mdlOutputs(t,x,u);
otherwise
DAStudio.error('Simulink:blocks:unhandledFlag', num2str(flag));
end
function [sys,x0,str,ts]=mdlInitializeSizes %
sizes = simsizes;
sizes.NumContStates = 0; %
sizes.NumDiscStates = 0; %
sizes.NumOutputs = 1; %
sizes.NumInputs = 4; %
sizes.DirFeedthrough = 1; %u1
sizes.NumSampleTimes = 0; %
% 1.
% nn个状态的系统状态
sys = simsizes(sizes);
x0 = []; %
str = []; %
ts = []; % [t1 t2] t1为采样周期t1=-1t2为偏移量0
global W
% 5-9-1 IN = 5 MID = 9 OUT = 1
%
W = [0 0 0 0 0 0 0 0 0]' ; %MID * OUT矩阵 9*1
function sys = mdlOutputs(t,x,u) %
global W
% 5-9-1
b = 20; % MID * 1 1*1 b的选择很重要 b越大
c = [-2 -1.5 -1 -0.5 0 0.5 1 1.5 2;
-2 -1.5 -1 -0.5 0 0.5 1 1.5 2;
-2 -1.5 -1 -0.5 0 0.5 1 1.5 2;
-2 -1.5 -1 -0.5 0 0.5 1 1.5 2;
-2 -1.5 -1 -0.5 0 0.5 1 1.5 2]; % IN * MID 5*9
% 仿 c和b b或c均会导致结果不正确
IN = 5;
Mid = 9;
Out = 1;
lambda = 5;
ita = 500 * eye(9);
xite = 0.005;
If = 0.25;
e = -u(1); % e = x - xd; -
de = -u(2);
x_1 = u(3);
x_2 = u(4);
s = lambda * e + de;
s_if = s/If;
yd = sin(t);
dyd = cos(t);
ddyd = -sin(t);
v = -ddyd + lambda * de;
Input = [x_1; x_2; s; s_if ; v];
h = zeros(Mid , 1); %9*1
for i =1:Mid
h(i) = exp(-(norm(Input - c(:,i))^2) / (2*b^2));
end
% ut
belta = 150;
ut = 1/belta * W' * h;
sys(1) = ut;
% W权值的更新
dw = -ita * (h * s + xite * W); % 9*9 * (9*1 + 9*1)
dt = 0.001; % 仿
W = W + dw * dt; % W的自适应律