function gershgorin(n,s);

% GERSHGORIN  Plot Gerschgorin circles.
% Gerschgorin circles are discs in the complex plane that contain
% the eigenvalues of a given matrix.
%
% GERSCHGORIN(A) plots the Gerschgorin cirles for the matrix A.
% A = gallery('smoke',n) for small n provides an interesting example.
%
% GERSCHGORIN(n,s) sets up a pushbutton that generates
% random n-by-n matrices with off-diagonal scale s.
% GERSCHGORIN, with no arguments, uses n = 7 and s = 0.1.

if nargin == 0
   gerschgorin(7,0.1);
   return
elseif nargin == 2
   clf
   set(gcf,'userdata',[n s])
   uicontrol('string','again','callback','gerschgorin(''again'')');
   gerschgorin('again')
   return
elseif isequal(n,'again')
   u = get(gcf,'userdata'); n = u(1); s = u(2);
   A = diag(randn(n,1)+i*randn(n,1)) + s*randn(n,n);
else
   A = n;
end 

%cla
hold on
D = diag(A);
A = A - diag(D);
colors = get(gca,'colororder');
circle = exp(2*pi*i*(0:64)/64);
for k = 1:size(A,1)
   disc = D(k) + norm(A(k,:),1)*circle;
   c = colors(mod(k-1,length(colors))+1,:);
   h=plot(real(D(k)),imag(D(k)),'.','color',c); set(h,'MarkerSize',14);
   plot(real(disc),imag(disc),'--','color',c);
   
 %  plot(real(D(:)),imag(D(:)),'*')
 %  plot(real(disc),imag(disc),'--');
   
end

axis equal
%hold off