資源簡介
This code contains the simulation of consensus in multi agent system control system.
代碼片段和文件信息
%==============
%2016.4.2
%===============
function?consensus
clc
clear
%%begin
N=input(‘請輸入N的值:‘);
a=cell(NN);%創建一個空的N*N矩陣
X=cell(1N);
Y=cell(1N);
d=cell(1N);
B=round(rand(NN));%由rand函數產生隨機數并四舍五入
A=tril(B-1)+triu(B‘0);%產生N*N對稱矩陣
L=diag(sum(A2))-A;%L=D-A
eig(L);%求L的全部特征值
for?i=1:N
????X{1i}=i;
????Y{1i}=0;
end
for?I=1:N
????d{1I}=[];
end
T0=0;
n=[];
for?k=1:1:1200
????for?j=1:N
????????b=0;
????????for?m=1:N
????????????b=b+A(jm)*(Y{1m}-Y{1j});%公式(2)累加
????????end
????
評論
共有 條評論