Spectral decomposition with Julia

We briefly discuss how to eigendecompose a symmetric square matrix, and check some of its properties.

Note about notation:

  • vectors are bold lowercase, like $\mathbf{u,v}$.
  • matrices are bold uppercase, like $\mathbf{A,B,C}$.
  • scalars are lowercase, like $x,y,z$.
  • ' means (i) the complex conjugate for scalars, or (ii) the (conjugate) transpose for vectors/matrices.
using LinearAlgebra: eigen, Diagonal, I, det, rank

Given an ordered basis every linear mapping has a unique transformation matrix. A way to characterize the matrix representation of the linear mapping is by how it transforms vectors. It turns out that we can find a set of special vectors that are just scaled by some eigenvalue when we apply the linear mapping to them.

Lets take a $4 \times 4$ matrix,

A = rand(4,4)

that is symmetric (or hermitic if elements were complex)

A = (A + A')/2

A $4 \times 4$ matrix has 4 eigenvalues $(e_1,e_2,e_3,e_4)$ and 4 respective eigenvectors $(\mathbf{v}_1,\mathbf{v}_2,\mathbf{v}_3,\mathbf{v}_4)$

e, U = eigen(A) # solves $Av = ev$

eigen returns the eigenvalues in a vector e and the eigenvectors as columns of a matrix U. E.g. the first eigenvalue is $e_1 =$ e[1] and the first eigenvector is $\mathbf{v}_1 =$ U[:,1]. Note that eigenvalues are ordered in descending order and eigenvectors reflect this reordering.

We can check that the secular equation $|\mathbf{A} - e_i\mathbf{I}| = 0$ is satisfied (for each eigenvalue)

for i in 1:4
   isapprox( det(A - e[i]*I), 0.00, atol=1e-4) || error("Secular equation $i not satisfied")
end

The corresponding eigenvectors satisfy $(\mathbf{A} - e_i\mathbf{I})\mathbf{v} = \mathbf{0}$

for i in 1:4
   isapprox( (A - e[i]*I)*U[:,i], fill(0.00,4), atol=1e-4) || error("a) Eigenvalue equation $i not satisfied")
end

or equivalently $\mathbf{A}\mathbf{v} = e_i\mathbf{v}$

for i in 1:4
   isapprox( A*U[:,i], e[i]*U[:,i], atol=1e-4) || error("b) Eigenvalue equation $i not satisfied")
end
  • If $\mathbf{A}$ is symmetric, thus $\mathbf{U}$ is orthonormal and $\mathbf{U}' = \mathbf{U}^{-1}$
  • If $\mathbf{A}$ is hermitic, thus $\mathbf{U}$ is unitary and $\mathbf{U}' = \mathbf{U}^{-1}$

In both cases it can be described as a similarity transformation $$ \mathbf{A} = \mathbf{U} \mathbf{D} \mathbf{U}^{-1} = \mathbf{U} \mathbf{D} \mathbf{U}' $$ where $\mathbf{D}$ is a diagonal matrix with the eigenvalues as diagonal elements. Therefore, $\mathbf{D}$ is the matrix that diagonalizes $\mathbf{A}$. $\mathbf{A}$ and $\mathbf{D}$ are said to be similar matrices.

A ≈ U * Diagonal(e) * U' || error("Not a similarity transformation")

A similarity transformation is also a conformal mapping. A matrix $\mathbf{W}$ encoding a crystallographic symmetry operation is an isometry if $$ \mathbf{G} \approx \mathbf{W} \mathbf{G} \mathbf{W}' $$ where $\mathbf{G}$ is the metric tensor.

Daniel Menéndez Crespo
Daniel Menéndez Crespo
Postdoctoral Associate

My research interests include topological quantum chemistry, chemical bonding and scientific computing..