%the input for this file is an nXn real matrix A, with n<9.
%The routine here computes
% the n Gerschgorin discs associated with the matrix A.
% currently, it displays the disc overlapping one with the other, so some
%of them may be hidden
color=['r', 'g', 'b',  'c', 'm', 'y' ,'w' ,'k'];
n=size(A); 

c=diag(A); r=sum(abs(A-diag(c))); eval=eig(A); %c= centers, r=radius
[rsorted,I]=sort(r);                           %we sort r, in order
					       %to generate the disc
					       %from largest to smallest
					       %so that the large discs
					       %will not hide the small ones
hold off
t=linspace(-pi,pi);
for i=n(2):-1:1
   x=c(I(i))+r(I(i))*cos(t); y=r(I(i))*sin(t);%generates a circle
   axis equal
   fill(x,y,color(I(i)))                         %fill the circle
   hold on
end
plot(real(eval),imag(eval),'k*')              %marks the eigenvalues 
A                                             %prints the original matrix...

