plot graph using eigenvalues and eigenvectors in r

main.py
import numpy as np
import matplotlib.pyplot as plt

# Generate a square matrix for demonstration
A = np.array([[3, 1], [1, 2]])

# Compute eigenvalues and eigenvectors
eigenvalues, eigenvectors = np.linalg.eig(A)

# Plot eigenvectors
origin = [0, 0]
plt.quiver(*origin, eigenvectors[0,0], eigenvectors[1,0], color='r', label='Eigenvector 1')
plt.quiver(*origin, eigenvectors[0,1], eigenvectors[1,1], color='b', label='Eigenvector 2')
plt.xlim(-1, 1)
plt.ylim(-1, 1)
plt.gca().set_aspect('equal', adjustable='box')
plt.legend()
plt.show()
538 chars
19 lines

gistlibby LogSnag