Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Path: blob/master/notebooks/Chapter 12 - Eigenvalues and Eigenvectors.ipynb
Views: 449
Eigenvalue and Eigenvector
An eigenvector of an matrix is a nonzero vector such that for some scalar . A scalar is called an eigenvalue of if there is a nontrivial solution of , such an is called an eigenvector corresponding to .
Rewrite the equation,
Since the eigenvector should be a nonzero vector, which means:
The column or rows of are linearly dependent
is not full rank, .
is not invertible.
, which is called characteristic equation.
Consider a matrix
Set up the characteristic equation,
Use SymPy charpoly
and factor
, we can have straightforward solutions for eigenvalues.
charpoly
returns characteristic equation.
Factor the polynomial such that we can see the solution.
From the factored characteristic polynomial, we get the eigenvalue, and has algebraic multiplicity of , because there are two . If not factored, we can use solve
instead.
Or use eigenvals
directly.
To find the eigenvector corresponding to , we substitute the eigenvalues back into and solve it. Construct augmented matrix with and perform rref.
The null space is the solution set of the linear system.
This is called eigenspace for , which is a subspace in . All eigenvectors are inside the eigenspace.
We can proceed with as well.
The null space is the solution set of the linear system.
To avoid troubles of solving back and forth, SymPy has eigenvects
to calcuate eigenvalues and eigenspaces (basis of eigenspace).
To clarify what we just get, write
NumPy Functions for Eigenvalues and Eigenspace
Convert SymPy matrix into NumPy float array.
.eigvals()
and .eig(A)
are handy functions for eigenvalues and eigenvectors.
An Example
Consider a matrix
Find eigenvalues.
Or use NumPy functions, show the eigenvalues.
And corresponding eigenvectors.
A Visualization Example
Let
find the eigenvalues and vectors, then visualize in
Use characteristic equation
There are two eigenvalues: and . Next we calculate eigenvectors.
The eigenspace for is
Any vector is eigenspace as long as is an eigenvector. Let's find out eigenspace for .
The eigenspace for is
Let's plot both eigenvectors as and and multiples with eigenvalues.
Geometric Intuition
Eigenvector has a special property that preserves the pointing direction after linear transformation.To illustrate the idea, let's plot a 'circle' and arrows touching edges of circle.
Start from one arrow. If you want to draw a smoother circle, you can use parametric function rather two quadratic functions, because cicle can't be draw with one-to-one mapping.But this is not the main issue, we will live with that.
Now, the same 'circle', but more arrows.
Now we will perform linear transformation on the circle. Technically, we can only transform the points - the arrow tip - that we specify on the circle.
We create a matrix
Align all the coordinates into two matrices for upper and lower half respectively.
The matrix multiplication and are linear transformation of the circle.
The circle becomes an ellipse. However, if you watch closely, you will find there are some arrows still pointing the same direction after linear transformation.
We can plot the cirle and ellipse together, those vectors pointing the same direction before and after the linear transformation are eigenvector of , eigenvalue is the length ratio between them.