Free cookie consent management tool by TermsFeed Finding the eigenvalues and the eigenvectors of a Hermitian matrix using NumPy | Pythontic.com

Finding the eigenvalues and the eigenvectors of a Hermitian matrix using NumPy

Overview:

  • If a matrix A is equal to its conjugate transpose then matrix A is called a Hermitian Matrix.

  • Obtaining the conjugate transpose of matrix involves two steps

    • Get the transpose of the matrix

    • Take the complex conjugate for each of the matrix elements

  • Complex conjugate of a complex number is another complex number with the same real part and the imaginary part with the opposite sign. Complex conjugate of a real number is the same number.

  • The main diagonal of a Hermitian matrix is all real numbers.

  • The eigh() function of the linalg module of the NumPy library computes and returns the eigenvalues and the eigenvectors of a given Hermitian matrix.

Example:

# Example Python program that uses eigh() to get the
# eigenvalues of a Hermitian Matrix

import numpy

# Construct a Hermitian matrix
hermitianMatrix = numpy.ndarray(shape = (2, 2),
                                   dtype = numpy.complex64)

hermitianMatrix[0][0] = 2
hermitianMatrix[0][1] = 2-2j
hermitianMatrix[1][0] = 2+2j
hermitianMatrix[1][1] = 3

print("Hermitian matrix:")
print(hermitianMatrix)
eigVals = numpy.linalg.eigh(hermitianMatrix)

print("Eigenvalues of the Hermitian matrix:")
print(eigVals[0])

print("Eigenvectors of a Hermitian matrix:")
print(eigVals[1])

Output:

Hermitian matrix:
[[2.+0.j 2.-2.j]
 [2.+2.j 3.+0.j]]
Eigenvalues of the Hermitian matrix:
[-0.3722813  5.3722816]
Eigenvectors of a Hermitian matrix:
[[-0.76618457-0.j         -0.64262056+0.j        ]
 [ 0.45440134+0.45440134j -0.54177433-0.54177433j]]

 


Copyright 2025 © pythontic.com