Skip to content

Eigenvalues & Eigenvectors (SymPy)

Definition

Let \(A\) be an \(n\times n\) matrix (i.e. a square matrix). A non-zero vector \(\vec{v}\) is an eigenvector of \(A\) with eigenvalue \(\lambda\) if

\[ A\vec{v} = \lambda \vec{v} \]

Rewriting this equation, we see that \(\vec{v}\) is a solution of the homogeneous system of equations

\[ (A-\lambda I) \vec{v} = \vec{0} \]

where \(I\) is the identity matrix of size \(n\). Non-trivial solutions exists only when the matrix \(A-\lambda I\) is noninvertible (singular). That is, when \(\operatorname{det}(A-\lambda I) =0\). Therefore, the eigenvalues are the roots of the characteristic polynomial

\[ p_A(\lambda) = \operatorname{det}(A-\lambda I) \]

Here are three examples that we will consider. In each case, we have pre-computed the eigenvalues and eigenvectors (check them yourself).

\[ A = \begin{bmatrix} 2 & 2 \\ 1 & 3 \end{bmatrix} , \quad \lambda_1 = 1 , \vec{v}_1 = \begin{bmatrix} -2 \\ 1 \end{bmatrix} , \quad \lambda_2 = 4 , \vec{v}_2 = \begin{bmatrix} 1 \\ 1 \end{bmatrix} \]
\[ B = \begin{bmatrix} 17 & -15 \\ 20 & -18 \end{bmatrix} , \quad \lambda_1 = 2 , \vec{v}_1 = \begin{bmatrix} 1 \\ 1 \end{bmatrix} , \quad \lambda_2 = -3 , \vec{v}_2 = \begin{bmatrix} 3 \\ 4 \end{bmatrix} \]
\[ C = \begin{bmatrix} -3 & 5 & -5 \\ -7 & 9 & -5 \\ -7 & 7 & -3 \end{bmatrix} , \quad \lambda_1 = -3 , \vec{v}_1 = \begin{bmatrix} 1 \\ 1 \\ 1 \end{bmatrix} , \quad \lambda_2 = 4 , \vec{v}_2 = \begin{bmatrix} 0 \\ 1 \\ 1 \end{bmatrix} , \quad \lambda_3 = 2 , \vec{v}_3 = \begin{bmatrix} 1 \\ 1 \\ 0 \end{bmatrix} \]
\[ D = \begin{bmatrix} 1 & 2 & -2 \\ 2 & 1 & 2 \\ -2 & 2 & 1 \end{bmatrix} , \quad \lambda_1 = 3 , \vec{v}_{1,1} = \begin{bmatrix} 1 \\ 1 \\ 0 \end{bmatrix} , \vec{v}_{1,2} = \begin{bmatrix} -1 \\ 0 \\ 1 \end{bmatrix} , \quad \lambda_2 = -3 , \vec{v}_2 = \begin{bmatrix} 1 \\ -1 \\ 1 \end{bmatrix} \]

Notice, for matrix \(D\) there is one eigenvalue that has two associated eigenvectors.

Warning

Eigenvectors are not unique, any scalar multiple of an eigenvector is an eigenvector. Therefore, some caution is needed when having software compute eigenvectors, they may not be exactly the ones you computed by hand.

from scipy import *

.eigenvals

To find the eigenvalues of a matrix, use the .eigenvals method. eigenvals returns a dictionary of eigenvalue: algebraic_multiplicity pairs.

.eigenvects

To find the eigenvectors of a matrix, use the .eigenvects method. eigenvects returns a list of tuples of the form (eigenvalue, algebraic_multiplicity, [eigenvectors]).

Example

Determine the eigenvalues and eigenvectors of

\[ A = \begin{bmatrix} 2 & 2 \\ 1 & 3 \end{bmatrix} \]
A = Matrix([[2,2],[1,3]])
A.eigenvals()
{4: 1, 1: 1}

The eigenvalues are \(1\) and \(4\).

A.eigenvects()
\(\left[ \left( 1,1,\left[ \left[\begin{matrix} -2 \\ 1 \end{matrix}\right] \right] \right), \left( 4,1,\left[ \left[\begin{matrix} 1 \\ 1 \end{matrix}\right] \right] \right) \right]\)

and the corresponding eigenvectors are \(\begin{bmatrix}-2 \\ 1 \end{bmatrix}\) and \(\begin{bmatrix} 1 \\ 1\end{bmatrix}\).

We can check this for ourself.

v1 = A.eigenvects()[0][2][0]
A*v1 == v1
True
v2 = A.eigenvects()[1][2][0]
A*v2 == 4*v1
True

Example

Determine the eigenvalues and eigenvectors of

\[ B = \begin{bmatrix} 17 & -15 \\ 20 & -18 \end{bmatrix} \]
B = Matrix([[17,-15],[20,-18]])
pprint(B.eigenvects())

\(\left[ \left( -3,1,\left[ \left[\begin{matrix} 3/4 \\ 1 \end{matrix}\right] \right] \right), \left( 2,1,\left[ \left[\begin{matrix} 1 \\ 1 \end{matrix}\right] \right] \right) \right]\)

Example

Determine the eigenvalues and eigenvectors of

\[ C = \begin{bmatrix} -3 & 5 & -5 \\ -7 & 9 & -5 \\ -7 & 7 & -3 \end{bmatrix} \]
C= Matrix([[-3,5,-5],[-7,9,-5],[-7,7,-3]])
C.eigenvects()

\(\left[ \left( -3,1,\left[ \left[\begin{matrix} 1 \\ 1 \\ 1 \end{matrix}\right] \right] \right), \left( 2,1,\left[ \left[\begin{matrix} 1 \\ 1 \\ 0 \end{matrix}\right] \right] \right), \left( 4,1,\left[ \left[\begin{matrix} 0 \\ 1 \\ 1 \end{matrix}\right] \right] \right) \right]\)

Example

Determine the eigenvalues and eigenvectors of

\[ D = \begin{bmatrix} 1 & 2 & -2 \\ 2 & 1 & 2 \\ -2 & 2 & 1 \end{bmatrix} \]
D = Matrix([[1,2,-2],[2,1,2],[-2,2,1]])
D.eigenvects()

\(\left[ \left( -3,1,\left[ \left[\begin{matrix} 1 \\ -1 \\ 1 \end{matrix}\right] \right] \right), \left( 3,2,\left[ \left[\begin{matrix} 1 \\ 1 \\ 0 \end{matrix}\right], \left[\begin{matrix} -1 \\ 0 \\ 1 \end{matrix}\right] \right] \right) \right]\)

The eigenvalue \(3\) has algebraic multiplicity \(2\), and since there are two corresponding linearly independent eigenvectors it also has geometric multiplicity \(2\).