Code Explanation:
1. Importing the Library
import numpy as np
numpy is imported using the alias np, which is a standard convention.
NumPy provides powerful mathematical functions and operations for matrix manipulations.
2. Defining the Matrix
matrix = np.array([[2, -1], [-1, 2]])
Here, a 2x2 matrix is defined using np.array().
3. Calculating Eigenvalues and Eigenvectors
eigenvalues, eigenvectors = np.linalg.eig(matrix)
The np.linalg.eig() function from NumPy’s linear algebra module (linalg) is used to compute the eigenvalues and eigenvectors.
Eigenvectors are the corresponding vectors that satisfy this equation.
4. Printing the Eigenvalues
print(eigenvalues)
This prints the eigenvalues of the matrix.
For the given matrix, the characteristic polynomial is:
∣A−λI∣=0
0 Comments:
Post a Comment