
% Construct an expander graph


  n=10;
  adj=sparse(n^2,n^2);
  for x=0:n-1
     for y=0:n-1
          vert1=1+x+n*y;
          adj(vert1, 1+mod(x+2*y,n)+n*y)=1;
          adj(vert1, 1+mod(x-2*y,n)+n*y)=1;
          adj(vert1, 1+mod(x+2*y+1,n)+n*y)=1;
          adj(vert1, 1+mod(x-2*y-1,n)+n*y)=1;
          adj(vert1, 1+x+ n*mod(y+2*x,n))=1;
          adj(vert1, 1+x+ n*mod(y-2*x,n))=1;
          adj(vert1, 1+x+ n*mod(y+2*x+1,n))=1;
          adj(vert1, 1+x+ n*mod(y-2*x-1,n))=1;
     end % for y 
  end % for  x

  min(sum(adj))
  
  eigs(adj)
  


  n=10;
  adj2=sparse(n^2,n^2);
  for x=0:n-1
     for y=0:n-1
          vert1=1+x+n*y;
          adj2(vert1, 1+mod(x+2*y,n)+n*y)= adj2(vert1, 1+mod(x+2*y,n)+n*y)+1;
          adj2(vert1, 1+mod(x-2*y,n)+n*y)= adj2(vert1, 1+mod(x-2*y,n)+n*y)+1;
          adj2(vert1, 1+mod(x+2*y+1,n)+n*y)=adj2(vert1, 1+mod(x+2*y+1,n)+n*y)+1; 
          adj2(vert1, 1+mod(x-2*y-1,n)+n*y)= adj2(vert1, 1+mod(x-2*y-1,n)+n*y)+1;
          adj2(vert1, 1+x+ n*mod(y+2*x,n))= adj2(vert1, 1+x+ n*mod(y+2*x,n))+1;
          adj2(vert1, 1+x+ n*mod(y-2*x,n))= adj2(vert1, 1+x+ n*mod(y-2*x,n))+1;
          adj2(vert1, 1+x+ n*mod(y+2*x+1,n))= adj2(vert1, 1+x+ n*mod(y+2*x+1,n))+1;
          adj2(vert1, 1+x+ n*mod(y-2*x-1,n))= adj2(vert1, 1+x+ n*mod(y-2*x-1,n))+1;


     end % for y 
  end % for  x

  min(sum(adj2))
  [D,V]=eigs(adj2)

   m=1000;
   n=2*m;
   randexp=sparse(n,n);
   for k=1:n-1
     randexp(k,k+1)=1;
     randexp(k+1,k)=1;
   end % for k
   randexp(n,1)=1;
   randexp(1,n)=1;
   p=randperm(m);
   for k=1:m
      randexp(k,m+p(k))=1;
      randexp(m+p(k),k)=1;
   end % for k

  min(sum(randexp))
  [D,V]=eigs(randexp)
   
   A=sparse(n,n);
   for k=1:20
      A=A+randexp^k;
      m(k)=min(min(A));
  end % for k
  m


