% Matlab code for verifying, on an example, that the adjacency matrix
% of an undirected graph weighted according to the equal-neighbor model
% is reversible


% A_bin: binary matrix of the graph
A_bin=[0 1 0 0;
    0 0 1 0;
    0 0 0 1
    0 1 0 0];
A_bin=A_bin+A_bin';

% compute A with the equal-neighbor weights
D=diag(sum(A_bin,2));
A_en=inv(eye(4)+D)*(eye(4)+A_bin);

% compute the left dominant eigenvector of A_en
[V,eigs]=eig(A_en');
% find the position of the dominant eigenvalue
[Y,I] = max(abs(diag(eigs)))
% extract the dominant eigenvector 
w=V(:,I);

% veryfy that diag(w)*A_en=A_en^T*diag(w)
diag(w)*A_en

A_en'*diag(w)
