Python Program to Find Eigenvalues and Eigenvectors

Program Code

import numpy as np

A = np.array([[1,2,3],[4,5,6],[7,8,9]])

eigenvalues, eigenvectors = np.linalg.eig(A)

print(f"The eigenvalues are {eigenvalues}")
print(f"The eigenvectors are {eigenvectors}")

Expected Output:

The eigenvalues are [ 1.61168440e+01 -1.11684397e+00 -1.30367773e-15]
The eigenvectors are [[-0.23197069 -0.78583024 0.40824829]
[-0.52532209 -0.08675134 -0.81649658]
[-0.8186735 0.61232756 0.40824829]]

Code Explanation

  1. We import the numpy library as np.
  2. We create a 3×3 matrix A.
  3. We use the eig() function to calculate the eigenvalues and eigenvectors of A.
  4. We print the eigenvalues and eigenvectors.

Leave a Comment

Share to...