Eigenvalues and eigenvectors

We'll work through finding the eigenvalues and bases for the eigenvectors for a specific matrix:

$$ \left[ \begin{array}{rrrr} 9&-4&-2&-4\\ -56&32&-28&44\\ -14&-14&6&-14\\ 42&-33&21&-45 \end{array} \right] $$

Let's go for it.

In [8]:
from sympy import *
init_printing(use_latex='mathjax')
In [9]:
M=Matrix([[9,-4,-2,-4],[-56,32,-28,44],[-14,-14,6,-14],[42,-33,21,-45]])
M
Out[9]:
$\displaystyle \left[\begin{matrix}9 & -4 & -2 & -4\\-56 & 32 & -28 & 44\\-14 & -14 & 6 & -14\\42 & -33 & 21 & -45\end{matrix}\right]$

Getting eigenvalues is as easy as calling the eigenvals method on the matrix:

In [10]:
M.eigenvals()
Out[10]:
$\displaystyle \left\{ -12 : 2, \ 13 : 2\right\}$

That says that it has eigenvalues $-12$ and $13$, each with algebraic multiplicity $2$: see Definition 8.40 of your textbook for the notion of algebraic multiplicity for an eigenvalue.

Now, how about eigenvectors? Just as easy:

In [11]:
M.eigenvects()
Out[11]:
$\displaystyle \left[ \left( -12, \ 2, \ \left[ \left[\begin{matrix}\frac{2}{7}\\1\\1\\0\end{matrix}\right], \ \left[\begin{matrix}0\\-1\\0\\1\end{matrix}\right]\right]\right), \ \left( 13, \ 2, \ \left[ \left[\begin{matrix}- \frac{1}{2}\\0\\1\\0\end{matrix}\right], \ \left[\begin{matrix}\frac{1}{3}\\- \frac{4}{3}\\0\\1\end{matrix}\right]\right]\right)\right]$

So: the eigenspace for eigenvalue $-12$ has dimension $2$ (i.e. the geometric multiplicity of the eigenvalue $-12$ is also $2$, just like its algebraic multiplicity), and the vectors

$$ \left[ \begin{array}{r} \frac 27\\ 1\\ 1\\ 0 \end{array} \right] \text{ and } \left[ \begin{array}{r} 0\\ -1\\ 0\\ 1 \end{array} \right] $$

form a basis for it. Similarly for the other eigenvalue. How about a quick sanity check that these indeed are eigenvectors? I'll pick one for each eigenvalue, being careful to define the entries as Rational numbers so they don't get rounded; that would lead to rounding errors, as described in this longer document I linked a long time ago on our class web page.

In [12]:
v0=Matrix([Rational(2,7),1,1,0])
v1=Matrix([Rational(1,3),-Rational(4,3),0,1])
v0, v1
Out[12]:
$\displaystyle \left( \left[\begin{matrix}\frac{2}{7}\\1\\1\\0\end{matrix}\right], \ \left[\begin{matrix}\frac{1}{3}\\- \frac{4}{3}\\0\\1\end{matrix}\right]\right)$

OK, now for the check. I want v0 to be an eigenvector for $M$, with eigenvalue $-12$, and similarly, I want v1 to be an eigenvector with eigenvalue $13$. So, recalling that eye(n) means the $n\times n$ identity matrix in SymPy, I can do

In [13]:
(M+12*eye(4))*v0
Out[13]:
$\displaystyle \left[\begin{matrix}0\\0\\0\\0\end{matrix}\right]$

Yes, that worked: it tells me that indeed

$$ (M+12I_4)v_0 = 0, $$

so

$$ Mv_0 = -12 v_0. $$

Now for the other one:

In [14]:
(M-13*eye(4))*v1
Out[14]:
$\displaystyle \left[\begin{matrix}0\\0\\0\\0\end{matrix}\right]$

Confirmed again: v1 is an eigenvector with eigenvalue $13$, because $Mv_1=13v_1$.