Gershgorin discs - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: General (https://python-forum.io/forum-1.html) +--- Forum: Code sharing (https://python-forum.io/forum-5.html) +--- Thread: Gershgorin discs (/thread-31942.html) |
Gershgorin discs - Pythia8 - Jan-11-2021 Showing how the Gershgorin discs coincide with the spectrum for a diagonal matrix. In the first image is the original matrix as the scaling factor p=1 and, in the following images the off-diagonal elements are scaled away by decreasing p. Hence, the diagonal elements approaches the eigenvalues and the Gerschgorin discs decreases in radius and disappears. Bold circles represents eigenvalues and pluses are midpoints of the circles. from pylab import * import scipy.linalg as sl import matplotlib.pyplot as plt A = array([[5,0,0,-1] ,[1,0,-3,1] ,[-1.5,1,-2,1] ,[-1,5,3,-3]]) pval = np.arange(0, 1.1, 0.1) k = len(A) i = 0 def scaled(A,p): A = (p*(ones((4,4)) -eye(4)) +eye(4))*A return A def gerschgorin(B): B = scaledA - diag(scaledA)*eye(k) radvec = zeros(k) for i in range(k): radvec[i] = sum(abs(B[i,:])) return radvec for p in pval: scaledA = scaled(A,p) radius = gerschgorin(scaledA) fig,ax = plt.subplots() for i in range(k): circle = plt.Circle((A[i,i],0), radius[i], fill=False) ax.add_artist(circle) z = sl.eig(scaledA)[0] plt.scatter(z.real, z.imag, marker="o", c="black") plt.scatter(diag(A), zeros(k), marker="+", c="black") plt.axis('equal') plt.xlim(-7.5, 7.5) plt.title('Eigenvalues of scaled matrix p={0:.2f}'.format(round(p,2))) plt.xlabel('eigenvalue real part') plt.ylabel('eigenvalue imaginary part') plt.show() plt.close() i+=1 RE: Gershgorin discs - Gribouillis - Jan-11-2021 Nice! You could add a slider widget in the plot to allow dynamic adjustment of p. There is a slider demo in the matplotlib documentation. |