%
% connmatrix.m
%
% makes an N by N matrix with m nonzeros per row, but always keeping the
% diagonal all zeros.
% then finds log of the absolute value of eigenvalues
% then writes an XPP table file to use for coupling called m2.tab
%  matlab code due to Zack Kilpatrick
N = 20;  % size of matrix
m = 5;   % number of ones per row
M = zeros(N);   % initialize matrix
for j = 1:N,
    ro = [ones(1,m) zeros(1,N-m-1)];  % row vector with m ones
    rr = rand(N-1,1);
    [junk,ind] = sort(rr);
    nro = ro(ind);                    % randomly permute row vector
    M(j,:) = [nro(1:j-1), 0, nro(j:end)];
end
M = M/m;    % scale so rows sum to 1.
  e=log(abs(eigs(M,N)))   % gives absolute value eigenvalues of matrix
  B=reshape(M',400,1);
  Bh=[400 0 399]';
  Bt=vertcat(Bh,B);
  dlmwrite('m2.tab',Bt);
