Gershgorin circle theorem roughly states that the eigenvalues of an matrix lie inside circles where -th circle is centred at and its radius is the sum of the absolute values of the off-diagonal entries of the -th row of . Applying this to implies that the radius of this circles shall be the smaller of the sums for rows and columns. The following Sage code draws the circles for a given matrix.
def Gershgorin(A,evals=False): # A is a square matrix # Output is the Gershgorin disks of A from sage.plot.circle import Circle from sage.plot.colors import rainbow n = A.ncols() Colors = rainbow(n, 'rgbtuple') E = point() B = A.transpose() R = [(A[i-1,i-1], min(sum( [abs(a) for a in (A[i-1:i]).list()] )-abs(A[i-1,i-1]),sum( [abs(a) for a in (B[i-1:i]).list()] )-abs(B[i-1,i-1]))) for i in range(1,n+1)] C = [ circle((real(R[i]),imaginary(R[i])), R[i], color="black") for i in range(n)] if evals == True: E = point(A.eigenvalues(), color="black", size=30) CF = [ circle((real(R[i]),imaginary(R[i])), R[i], rgbcolor=Colors[i], fill=True, alpha=1/n) for i in range(n)] (sum(C)+sum(CF)+E).show()
And here is a sample output:
A = random_matrix(CDF,4) Gershgorin(A)
If you want to see the actual eigenvalues, call the function as below: