Free cookie consent management tool by TermsFeed Finding the eigenvalues of a matrix | Pythontic.com

Finding the eigenvalues of a matrix

Overview:

  • Given a matrix the function eigvals() returns the eigen values of the matrix.
  • When a matrix is multiplied by a vector if the result is scalar times of that vector, the vector is known as eigenvector. The scalar value is known as eigenvalue.
  • The eigenvectors and eigenvalues exist only for square matrices.

Example:

# Example Python program that finds the eigenvalues of a matrix
import numpy 

# Control the printing format of floating point numbers
numpy.set_printoptions(suppress=True, formatter={'float_kind':'{:0.2f}'.format}) 

# Create a matrix
numbers = numpy.arange(-25, 20, 5)
matrix  = numbers.reshape(3, 3)
print("The matrix:")
print(matrix)

# Find the eigen values of the matrix
evs = numpy.linalg.eigvals(matrix)
print("Eigen values of the matrix:")
print(evs)

Output:

The matrix:

[[-25 -20 -15]

 [-10  -5   0]

 [  5  10  15]]

Eigen values of the matrix:

[-30.00 0.00 15.00]

 


Copyright 2025 © pythontic.com