Assign5part1

mail@pastecode.io avatar
unknown
python
2 years ago
1.2 kB
2
Indexable
Never
import numpy as np
import matplotlib.pyplot as plt

Adiag = np.array([[5, 0, 0, 0],[0, 0, 0, 0], [0, 0, -2, 0], [0, 0, 0, -3]])
A = np.array([[5, 0, 0, -1], [1, 0, -1, 1], [-1.5, 1, -2, 1], [-1, 1, 3, -3]])

for i in range(0,11):
    p = i/10
    Ap = p*(A-Adiag) + Adiag
    e,_= np.linalg.eig(Ap)
    # extract real part
    x = [ele.real for ele in e]
    # extract imaginary part
    y = [ele.imag for ele in e]
  
    # plot the complex numbers
    #plt.scatter(x, y, marker = '.')
    #plt.scatter(np.diagonal(Adiag), [0, 0, 0,0], marker = 'o')
    plt.xlim([-8, 6])
    plt.ylim([-5,5])
    figure, axes = plt.subplots()
    #figure = plt.gcf()
    #axes = figure.gca()
    c1 = plt.Circle((5, 0), p*1, fill = False )
    c2 = plt.Circle((0, 0), p*3, fill = False)
    c3 = plt.Circle((-2, 0), p*3.5, fill = False )
    c4 = plt.Circle((-3, 0), p*5, fill = False)
    plt.scatter(x, y, marker = '.')
    plt.scatter(np.diagonal(Adiag), [0, 0, 0,0], marker = 'o')
    plt.scatetr()
    plt.xlim([-8, 6])
    plt.ylim([-5,5])
    plt.ylabel('Imaginary')
    plt.xlabel('Real')
    plt.title(f'p = {p}')
    
    axes.add_patch(c1)
    axes.add_patch(c2)
    axes.add_patch(c3)
    axes.add_patch(c4)