Code Explanation:
1. Importing the NumPy Library
import numpy as np
NumPy is a fundamental Python library for numerical computations.
It provides functions for working with arrays, matrices, linear algebra, and more.
The alias np is a common convention for importing NumPy.
2. Creating a Matrix Using NumPy
matrix = np.array([
[4, 2],
[1, 3]])
np.array() is used to create a NumPy array representing a matrix.
The matrix is a 2x2 square matrix with 2 rows and 2 columns.
3. Understanding Eigenvalues and Eigenvectors
Eigenvalues and Eigenvectors are fundamental concepts in linear algebra.
For a square matrix ๐ด
A, if there exists a scalar ๐
ฮป and a non-zero vector ๐ฃ
v such that:๐ด⋅๐ฃ=๐⋅๐ฃ
Then:
ฮป is called an eigenvalue
v is called the corresponding eigenvector.
Finding Eigenvalues Using NumPy
eigenvalues, eigenvectors = np.linalg.eig(matrix)
np.linalg.eig() is a NumPy function used to calculate eigenvalues and eigenvectors of a square matrix.
It returns:
eigenvalues: A NumPy array of the eigenvalues.
eigenvectors: A matrix where each column represents an eigenvector.
4. Rounding the Eigenvalues
print(np.round(eigenvalues, 2))
np.round() is used to round the eigenvalues to two decimal places for clearer output.
It makes results more readable and is especially useful for complex numbers.
5. Calculation of Eigenvalues (Manual Method)
The characteristic polynomial of matrix ๐ด
A is:det(A−ฮปI)=0
Final Output
[5. 2.]
0 Comments:
Post a Comment