2
$\begingroup$

I have an $N \times N$ adjacency matrix $A_{ij}$ for nodes $i$ and $j$, numbered 1 through $N$. Each node $i$ starts with a scalar value $x_i(0)$ between 0 and 1. At each non-negative integral time $k$, node $i$ receives from some of the other nodes $j$ a message with the value of $x_j(k)$, and updates its value according to

$$X_i(k+1)= X_i(k)+ \sum_{j\in N_i} A_{ij}(X_j(k)-X_i(k))$$

How can I can write the MATLAB code for this algorithm? I have randomly initialized the adjacency matrix and initial values of each node.

For more information see http://www.eecs.harvard.edu/~rad/courses/cs266-fall07/papers/reza-tac07.pdf

1 Answers 1

0

I have modified your pseudocode to adjust the rate of descent, $c$.

N=10; M=2; c_0=0.15; X=rand(M,N); Xn=zeros(M,N);
A=round(rand(N,N));
A=round((A+A')/2);
A=max(eye(N),A);

error=Inf; goal=1e-6; steps=0; c=c_0;
while error>goal;
    Xn=X; steps=steps+1;
    for i=1:N
        for j=1:N
            Xn(:,i)=Xn(:,i)+c*((X(:,j)-X(:,i))*A(i,j));
        end
    end
    n_error=norm(var((Xn-repmat(mean(Xn')',[1 N]))'));
    if (n_error<10*goal)
        c=max(c_0/4,c/2);
    elseif n_error>5*goal
        c=min(c_0,2*c);
    end
    fprintf('Error: %f\n',error)    
    X=Xn; error=n_error;
    plot(X(1,:),X(2,:),'d')
    axis([0 1 0 1])
end
fprintf('Consensus reached in %i steps.',steps);
  • 0
    Emre here From X i obtained Xn so it is one iteration,How can i find Xn1 from Xn and Xn2 from X1 i mean how can i can create more iteration for same formula.Thank you2012-04-19
  • 0
    The number of iterations is stored in 'steps' and it is generally greater than one.2012-04-20