Two Directions That Stay Put

eigenvalues · eigenvectors · Hermitian matrices · quadratic formula · normalising

A 2 by 2 matrix is stored as a list of rows, m = [[a, b], [c, d]], with complex entries (ints and floats allowed too). It is Hermitian when it equals its own conjugate transpose: a and d are real and c is the conjugate of b (c == b.conjugate()).

A nonzero vector v with M v = \lambda v is an eigenvector of M with eigenvalue \lambda; here (Mv)_i = \sum_j M_{ij} v_j, with no conjugate. A Hermitian matrix has two real eigenvalues, and in this problem they are always different. Eigenvectors for different eigenvalues are orthogonal. In quantum computing, Hermitian matrices are the quantities you can measure, and their eigenvalues are the possible readings.

Write hermitian_eigen(m) that returns (low, high, v_low, v_high): the two eigenvalues with low < high, and for each one an eigenvector of length 1 (the sum of abs(x) ** 2 over its entries is 1), as a list of two numbers.

An eigenvector stays an eigenvector when multiplied by any number, so even at length 1 there is a choice: any factor of modulus 1 (like -1 or 1j) is accepted. [0.6, 0.8j], [-0.6, -0.8j] and [0.6j, -0.8] are all the same answer.

Examples

Input:  m = [[0, 1], [1, 0]]
Output: (-1.0, 1.0, [0.7071067811865475, -0.7071067811865475], [0.7071067811865475, 0.7071067811865475])
Explanation: M [1, -1] = [-1, 1] = -1 * [1, -1], and M [1, 1] = [1, 1]; both scaled to length 1.

Input:  m = [[2, 1j], [-1j, 2]]
Output: (1.0, 3.0, [0.7071067811865475j, -0.7071067811865475], [0.7071067811865475j, 0.7071067811865475])
Explanation: M [1j, -1] = [2j - 1j, 1 - 2] = [1j, -1], so 1 is an eigenvalue;
M [1j, 1] = [2j + 1j, 1 + 2] = [3j, 3], so 3 is the other. [1, 1j] for low is accepted too.

Input:  m = [[3, 0], [0, -2]]
Output: (-2.0, 3.0, [0, 1], [1, 0])

Constraints

  • m is Hermitian, its entries have modulus at most 100, and b is 0 or has modulus at least 0.001
  • the two eigenvalues differ by at least 0.01
  • answers are compared with a tolerance of 1e-6, each eigenvector up to a factor of modulus 1

Goals

  • Find both eigenvalues of a 2 by 2 Hermitian matrix from a quadratic equation
  • Find a unit eigenvector for each eigenvalue, including when the matrix is diagonal
  • Understand why an eigenvector is only defined up to a factor of modulus 1
Starting Python…