clear all
clc
tspan=[0,40];
y0=[7 6 2 1 0.5 -0.3 -0.5 -3.5 -5 -7.2];
[tt,yy]=ode45(@System1,tspan,y0);
yy1=yy.^2; %将矩阵的每一个元素平方
kase=sum(yy1,2);%对每行元素求和
L=[1 -1 0 0 0 0 0 0 0 0;
0 1 -1 0 0 0 0 0 0 0;
0 0 1 -1 0 0 0 0 0 0;
0 0 0 1 -1 0 0 0 0 0;
0 0 0 0 1 -1 0 0 0 0;
0 0 0 0 0 1 -1 0 0 0;
0 0 0 0 0 0 1 -1 0 0;
0 0 0 0 0 0 0 1 -1 0;
0 0 0 0 0 0 0 0 1 -1;
-1 0 0 0 0 0 0 0 0 1] %计算第二小特征值是注意要改变系统的状态方程
landa=eig(L);
landa2=real(landa(2));
subplot(2,1,1);
figure(1);
plot(tt,yy(:,1));
hold on;
plot(tt,yy(:,2));
hold on;
plot(tt,yy(:,3));
hold on;
plot(tt,yy(:,4));
hold on;
plot(tt,yy(:,5));
hold on;
plot(tt,yy(:,6));
hold on;
plot(tt,yy(:,7));
hold on;
plot(tt,yy(:,8));
hold on;
plot(tt,yy(:,9));
hold on;
plot(tt,yy(:,10));
axis([0 40 -10 10]);
xlabel('time(sec)');
ylabel('node value');
grid;
title('Algebraic Connectivity=0.191');
subplot(2,1,2);
plot(tt,kase);
axis([0 40 0 200]);
xlabel('time(sec)');
ylabel('disagreement');
grid;