資源簡(jiǎn)介
This code contains the simulation of consensus in multi agent system control system.
代碼片段和文件信息
%==============
%2016.4.2
%===============
function?consensus
clc
clear
%%begin
N=input(‘請(qǐng)輸入N的值:‘);
a=cell(NN);%創(chuàng)建一個(gè)空的N*N矩陣
X=cell(1N);
Y=cell(1N);
d=cell(1N);
B=round(rand(NN));%由rand函數(shù)產(chǎn)生隨機(jī)數(shù)并四舍五入
A=tril(B-1)+triu(B‘0);%產(chǎn)生N*N對(duì)稱矩陣
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
????
評(píng)論
共有 條評(píng)論