Last active
June 8, 2021 07:48
-
-
Save shane5ul/fdd389e04395691170c0 to your computer and use it in GitHub Desktop.
demoGershgorin(A) plots the Gershgorin discs that bound the eigenvalues of a matrix A, and also the actual eigenvalues.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import matplotlib | |
from matplotlib.patches import Circle | |
from matplotlib.collections import PatchCollection | |
import matplotlib.pyplot as plt | |
from numpy import linalg as LA | |
def demoGerschgorin(A): | |
n = len(A) | |
eval, evec = LA.eig(A) | |
patches = [] | |
# draw discs | |
for i in range(n): | |
xi = np.real(A[i,i]) | |
yi = np.imag(A[i,i]) | |
ri = np.sum(np.abs(A[i,:])) - np.abs(A[i,i]) | |
circle = Circle((xi, yi), ri) | |
patches.append(circle) | |
fig, ax = plt.subplots() | |
p = PatchCollection(patches, cmap=matplotlib.cm.jet, alpha=0.1) | |
ax.add_collection(p) | |
plt.axis('equal') | |
for xi, yi in zip(np.real(eval), np.imag(eval)): | |
plt.plot(xi, yi,'o') | |
plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment