% consensus.m - simulation of connsensus protocol
% RMM, 10 Sep 06

aminit;					% initialize macros

% Construct the Laplacian corresponding to our network
L = [
   1 -1  0  0  0;
  -1  4 -1 -1 -1;
   0 -1  2 -1  0;
   0 -1 -1  2  0;
   0 -1  0  0  1;
];

% Now generate the discrete time dynamics matrix
gamma = 0.1;
A = eye(5) - gamma*L;

% Generate an initial set of measurements for the system
x0 = [10 15 25 35 40];

% Finally, simulate the dynamics for N time steps
clear('x'); x(:, 1) = x0; N = 40;
for k = 1:N-1
  x(:, k+1) = A * x(:, k);
end

% Now plot the results
figure(1); clf; subplot(321);
plot(0:N-1, x, 'b', 'LineWidth', AM_data_linewidth);
amaxis([0 N 10 40]);

xlabel('Iteration');
ylabel('Agent states {\itx}_{\iti}');

amprint('consensus.eps');
