Table of Contents
show
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
- We import the
numpy
library asnp
. - We create a 3×3 matrix
A
. - We use the
eig()
function to calculate the eigenvalues and eigenvectors ofA
. - We print the eigenvalues and eigenvectors.