3

A Hermitian matrix is a complex square matrix which is equal to its conjugate transpose. Its matrix elements fulfil following condition:

$$a_{ij} = \bar{a}_{ji}$$

Everytime, I compute eigenvectors of a Hermitian matrix using Python, the first coefficient of the eigenvector is a pure real number. Is this an attribute of Hermitian matrices?

I attach a code snippet to generate a Hermitian matrix, compute its eigenvectors and print the eigenvector corresponding to the lowest eigenvalue.

import numpy as np
from numpy import linalg as LA
N = 5   # Set size of a matrix
# Generate real part of the matrix at first
real_matrix = np.random.uniform(-1.0, 1.0, size=(N,N))
real_matrix = (real_matrix + real_matrix.T)/2
# Generate imaginary part of the matrix
imaginary_matrix = np.random.uniform(-1.0, 1.0, size=(N,N))
imaginary_matrix = (imaginary_matrix + imaginary_matrix.T)/2
imaginary_matrix = imaginary_matrix.astype(complex) * 1j
for row in range(N):
    for column in range(row,N):
        if row == column:
            imaginary_matrix[row][column] = 0.0
        else:
            imaginary_matrix[row][column] *= -1
# Combine real and imaginary part
matrix = real_matrix + imaginary_matrix
# Compute and print eigenvector
eigenvalues, eigenvectors = LA.eigh(matrix)
print(eigenvectors[:,0])
Jakub Wagner
  • 428
  • 1
  • 5
  • 15
  • 4
    This question is probably better suited for [math.se], if it is [on-topic](https://math.stackexchange.com/help/on-topic) per that site's posting rules. – pault May 02 '18 at 18:48
  • 1
    I will ask there too. I am not sure if it is caused by the LA.eigh function or if it is a general mathematical rule. – Jakub Wagner May 02 '18 at 18:52
  • The link to question at [Mathematics](https://math.stackexchange.com/) is [here](https://math.stackexchange.com/questions/2763826/eigenvectors-of-a-hermitian-matrix). – Jakub Wagner May 02 '18 at 19:10
  • 1
    @WarrenWeckesser the question may be a bit misleading, see what he's printing. A Hermitian matrix has real eigenvalues and orthogonal eigenvectors. No such property as _the first coefficient of the eigenvector is a pure real number_ – filippo May 02 '18 at 19:53
  • @filippo Ah, I didn't read closely enough. Thanks! – Warren Weckesser May 02 '18 at 20:06
  • 3
    @pault I disagree, to me it is an implementation question, not a mathematical question. – P. Camilleri May 02 '18 at 20:41
  • 1
    @PCamilleri I read *"Is this an attribute of Hermitian matrices?"* as a math question but you have a point. – pault May 02 '18 at 21:24
  • The question was closed for the stated reason "does not appear to be about programming", which is simply—plainly—wrong. It is a *specific* question about a *software algorithm* for eigendecomposition that is part of the "scipy" *software tool*, that is both *practical* and *answerable*. Neither do any of the commonly-stated quality issues apply here. I can see no reason why this question should have been closed. If this truly "does not meet Stack Overflow guidelines", then said guidelines need to be revised for clarity. – MRule Aug 30 '22 at 12:53

1 Answers1

5

I think it's a python question rather than a mathematics question.

You have some ambiguity when performing an eigenvalue decomposition: if u is a unitary eigenvector for the eigenvalue lambda, then exp(i theta) * u is also a unitary eigenvector (for any real theta) for the same eigenvalue. To fix this indetermination, some implementation impose that the first coefficient of each eigenvector is real.

You get the same thing when doing an eigendecomposition of a real matrix: if u is an eigenvector, - u also is. To make the eigendecomposition deterministic, some implementation (for example sklearn's PCA, see this related question) impose that the greatest coefficient of u in magnitude be positive.

P. Camilleri
  • 12,664
  • 7
  • 41
  • 76