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.
from sympy import *
init_printing(use_latex='mathjax')
M=Matrix([[9,-4,-2,-4],[-56,32,-28,44],[-14,-14,6,-14],[42,-33,21,-45]])
M
Getting eigenvalues is as easy as calling the eigenvals
method on the matrix:
M.eigenvals()
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:
M.eigenvects()
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.
v0=Matrix([Rational(2,7),1,1,0])
v1=Matrix([Rational(1,3),-Rational(4,3),0,1])
v0, v1
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
(M+12*eye(4))*v0
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:
(M-13*eye(4))*v1
Confirmed again: v1
is an eigenvector with eigenvalue $13$, because $Mv_1=13v_1$.