分享一个之前写的二阶的仿真模型
系统是二阶的
{ p ˙ = v v ˙ = u \left\{\begin{aligned} \dot{p} = v \\ \dot{v} = u \\ \end{aligned}\right. {p˙=vv˙=u
含有时滞
做了离散化处理
% 多智能体系统一致性的控制基础及其应用
% 第7章二阶连续时间含时滞
% Author: Zhao-Jichao
% Date: 2021-06-02
clear
clc%% Laplacian Matrix
L = [1 0 0 -1-1 1 0 00 -1 1 00 0 -1 1];
% a = [0, 0, 0.1, 0, 0;
% 0.1, 0, 0, 0, 0;
% 0, 0.15, 0, 0, 0;
% 0, 0.25, 0, 0, 0;
% 0.2, 0, 0, 0, 0;];
a = [0, 0, 1, 0, 0;1, 0, 0, 0, 0;0, 1, 0, 0, 0;0, 2, 0, 0, 0;2, 0, 0, 0, 0;];%% Initial States
X0 = [20 10 40 00 50];
dX0= [00 00 00 00 00];x1(1,1) = 20; dx1(1,1) = 00;
x2(1,1) = 10; dx2(1,1) = 00;
x3(1,1) = 40; dx3(1,1) = 00;
x4(1,1) = 00; dx4(1,1) = 00;
x5(1,1) = 00; dx5(1,1) = 00; %% Time parameters
tBegin = 0;
tFinal = 50;
dT = 0.01;
times = (tFinal-tBegin)/dT;
time(1,1) = 0;% Time delay
T1 = 20;
T2 = 20;
T3 = 20;
T4 = 20;
T5 = 20;T11 = 0; T12 = 0; T13 = 0; T14 = 0; T15 = 0;
T21 = 0; T22 = 0; T23 = 0; T24 = 0; T25 = 0;
T31 = 0; T32 = 0; T33 = 0; T34 = 0; T35 = 0;
T41 = 0; T42 = 0; T43 = 0; T44 = 0; T45 = 0;
T51 = 0; T52 = 0; T53 = 0; T54 = 0; T55 = 0;alpha = 1;
beta = 3;%% Iteration Calculate
for t=1:max([T1,T2,T3,T4])time(t+1,1) = time(t,1)+dT;x1(t+1,1) = x1(t,1);x2(t+1,1) = x2(t,1);x3(t+1,1) = x3(t,1);x4(t+1,1) = x4(t,1);x5(t+1,1) = x5(t,1);dx1(t+1,1) = dx1(t,1);dx2(t+1,1) = dx2(t,1);dx3(t+1,1) = dx3(t,1);dx4(t+1,1) = dx4(t,1);dx5(t+1,1) = dx5(t,1);
end
for t=(max([T1,T2,T3,T4])+1):times% record timestime(t+1,1) = time(t,1) + dT;% calculate control inputu1x = alpha * (a(1,2)*( x2(t-T12,:)- x1(t-T1,:)) + a(1,3)*( x3(t-T13,:)- x1(t-T1,:)) + a(1,4)*( x4(t-T14,:)- x1(t-T1,:)) + a(1,5)*( x5(t-T15,:)- x1(t-T1,:))) + ...beta * (a(1,2)*(dx2(t-T12,:)-dx1(t-T1,:)) + a(1,3)*(dx3(t-T13,:)-dx1(t-T1,:)) + a(1,4)*(dx4(t-T14,:)-dx1(t-T1,:)) + a(1,5)*(dx5(t-T15,:)-dx1(t-T1,:)));u2x = alpha * (a(2,1)*( x1(t-T21,:)- x2(t-T2,:)) + a(2,3)*( x3(t-T23,:)- x2(t-T2,:)) + a(2,4)*( x4(t-T24,:)- x2(t-T2,:)) + a(2,5)*( x5(t-T25,:)- x2(t-T2,:))) + ...beta * (a(2,1)*(dx1(t-T21,:)-dx2(t-T2,:)) + a(2,3)*(dx3(t-T23,:)-dx2(t-T2,:)) + a(2,4)*(dx4(t-T24,:)-dx2(t-T2,:)) + a(2,5)*(dx5(t-T25,:)-dx2(t-T2,:)));u3x = alpha * (a(3,1)*( x1(t-T31,:)- x3(t-T3,:)) + a(3,2)*( x2(t-T32,:)- x3(t-T3,:)) + a(3,4)*( x4(t-T34,:)- x3(t-T3,:)) + a(3,5)*( x5(t-T35,:)- x3(t-T3,:))) + ...beta * (a(3,1)*(dx1(t-T31,:)-dx3(t-T3,:)) + a(3,2)*(dx2(t-T32,:)-dx3(t-T3,:)) + a(3,4)*(dx4(t-T34,:)-dx3(t-T3,:)) + a(3,5)*(dx5(t-T35,:)-dx3(t-T3,:)));u4x = alpha * (a(4,1)*( x1(t-T41,:)- x4(t-T4,:)) + a(4,2)*( x2(t-T42,:)- x4(t-T4,:)) + a(4,3)*( x3(t-T43,:)- x4(t-T4,:)) + a(4,5)*( x5(t-T45,:)- x4(t-T4,:))) + ...beta * (a(4,1)*(dx1(t-T41,:)-dx4(t-T4,:)) + a(4,2)*(dx2(t-T42,:)-dx4(t-T4,:)) + a(4,3)*(dx3(t-T43,:)-dx4(t-T4,:)) + a(4,5)*(dx5(t-T45,:)-dx4(t-T4,:)));u5x = alpha * (a(5,1)*( x1(t-T51,:)- x5(t-T5,:)) + a(5,2)*( x2(t-T52,:)- x5(t-T5,:)) + a(5,3)*( x3(t-T53,:)- x5(t-T5,:)) + a(5,4)*( x4(t-T54,:)- x5(t-T5,:))) + ...beta * (a(5,1)*(dx1(t-T51,:)-dx5(t-T5,:)) + a(5,2)*(dx2(t-T52,:)-dx5(t-T5,:)) + a(5,3)*(dx3(t-T53,:)-dx5(t-T5,:)) + a(5,4)*(dx4(t-T54,:)-dx5(t-T5,:)));% update statuesdx1(t+1,1) = dx1(t,1) + dT*u1x;dx2(t+1,1) = dx2(t,1) + dT*u2x;dx3(t+1,1) = dx3(t,1) + dT*u3x;dx4(t+1,1) = dx4(t,1) + dT*u4x;dx5(t+1,1) = dx5(t,1) + dT*u5x;x1(t+1,1) = x1(t,1) + dT*dx1(t+1,1);x2(t+1,1) = x2(t,1) + dT*dx2(t+1,1);x3(t+1,1) = x3(t,1) + dT*dx3(t+1,1);x4(t+1,1) = x4(t,1) + dT*dx4(t+1,1);x5(t+1,1) = x5(t,1) + dT*dx5(t+1,1);
end%% Draw Graphs
subplot(2,1,1)
plot(time,x1, time,x2, time,x3, time,x4, time,x5, "linewidth",1.5);
legend("x_1", "x_2", "x_3", "x_4", "x_5"); grid onsubplot(2,1,2)
plot(time,dx1, time,dx2, time,dx3, time,dx4, time,dx4, "linewidth",1.5);
legend("dx_1", "dx_2", "dx_3", "dx_4", "dx_5"); grid on
% Time delay
T1 = 20;
T2 = 20;
T3 = 20;
T4 = 20;
T5 = 20;
% Time delay
T1 = 24;
T2 = 24;
T3 = 24;
T4 = 24;
T5 = 24;
% Time delay
T1 = 25;
T2 = 25;
T3 = 25;
T4 = 25;
T5 = 25;
本文链接:https://my.lmcjl.com/post/11134.html
展开阅读全文
4 评论