In order to successfully complete this assignment, you must do the required reading, watch the provided videos, and complete all instructions. The embedded survey form must be entirely filled out and submitted on or before 11:59pm on the day before class. Students must come to class the next day prepared to discuss the material covered in this assignment.
%matplotlib inline
import matplotlib.pylab as plt
import numpy as np
import sympy as sym
sym.init_printing()
Definition: A non-zero vector $x$ in $R^n$ is called an eigenvector of a $n\times n$ matrix $A$ if $Ax$ is a scalar multiple of $x$. If $Ax = \lambda x$, then $\lambda$ is called the eigenvalue of $A$ corresponding to $x$.
We want to find $\lambda$ and non-zero vector $x$ such that $Ax=\lambda x$ for a $n\times n$ matrix.
Let's calculate eigenvalues for the following matrix:
$$ A=\begin{bmatrix} 0 & 0 & -2 \\ 1 & 2 & 1 \\ 1 & 0 & 3 \end{bmatrix}$$Looking at the above recipe, let's solve the problem symbollically using sympy
. First lets create a matrix $B$ such that:
#Most sympy requires defeing the variables as "symbols"
#Once we do this we can use the variables in place of numbers
lam = sym.symbols('lambda')
A = sym.Matrix([[0, 0 ,-2], [1, 2, 1], [1, 0, 3]])
I = sym.eye(3)
B = A - lam*I
B
Now, per step 2, the determinate of $B$ must be zero. Note that sympy
calculates the determinate symbollically as follows:
B.det()
✅ **Do This:** Using the sympy.solve
function on the determinate of $B$ to solve for lam
($\lambda$). Verify that the solution to the last question produces the same eigenvalues as above.
# Put your code to solve for det(B) = 0 here
✅ **Do This:** First, let's use the built in funciton eigenvals
function in sympy
to calculate the eigenvalues. Find out the meaning of the output.
# Put your code here
Explain your output here.
Now we know the eigenvalues, we can substitue them back into the equation to find the eigenvectors.
We solve this symbollically using sympy
. First let's make a vector of our eigenvalues (from above):
eig = [1,2]
Now (per step 4 above) we need to solve the equation $(A-\lambda I)x=0$. One way to do this in sympy
is as follows:
x1,x2,x3 = sym.symbols(['x_1','x_2','x_3'])
x = sym.Matrix([[x1],[x2],[x3]])
x
for lam in eig:
vec = sym.solve((A - lam*I)*x,x)
print(vec)
✅ **QUESTION:** Explain your output here. (Hint, you can also try the rref
to find the solutions)
Put your answer here
✅ **Do This:** Next, let's use the eigenvects
function in sympy
to find three linear independent eigenvectors for the matrix $A$?
# Put your answer to the above question here
✅ **QUESTION:** Compare this answer to the eigenvectors we calculated above. Does this answer make sense? What does the syntax tell us?
Put your answer here
✅ **DO THIS:** Find the eigenvalues and eigenvectors of the following matrix: $$ A2=\begin{bmatrix} 2 & 1 \\ 0 & 2 \end{bmatrix}$$
✅ **QUESTION:** What are the eigenvalues for the matrix $A2$?
Put your answer to the above question here
✅ **QUESTION:** What are the eigenvectors for the matrix $A2$?
Put your answer to the above question here
In class we will be using matrix diagonalization to solve some problems.
Matrix $A$ is diagonalizable if there exists a diagonal matrix $D$ that is similar similar to $A$:
$$ D = C^{-1}AC$$If matrix $A$ has linearly independent eigenvectors ($v_1, \ldots v_n$) then $A$ is diagonalizable with the following solution:
$$C = \left[ v_1^T, \ldots, v_n^T \right]$$In other words, each column of $C$ is a linearly independent eigenvector of $A$. The diagonal matrix $D$ is
$$ D = \left[ \begin{matrix} \lambda_1 & 0 & 0 \\ 0 & \ddots & 0 \\ 0 & 0 & \lambda_n \end{matrix} \right] $$In other-other words, $D$ consists of the corresponding eigenvalues.
%matplotlib inline
import matplotlib.pylab as plt
import numpy as np
import sympy as sym
sym.init_printing(use_unicode=True)
✅ **DO THIS:** Using numpy
, Diagonalize (i.e. calculate C and D) the following matrix:
A = np.matrix([[5, -2, 2], [4, -3, 4], [4,-6,7]])
sym.Matrix(A)
# Put your answer here
from answercheck import checkanswer
checkanswer.matrix(D,'56821475223b52e0b6e751da444a1441');
✅ **DO THIS:** Verify that $A$ is in fact Diagonalizable by calculating $D2 = C^{-1}AC$ and comparing it to your original $D$ using np.allclose
.
#Put your verificaiton code here.
np.allclose(D,D2)
One special case is Symmetric Matrices. It can be shown that symmetric Matrices are Diagonalizable and the resulting eigenvectors are not only linearly independent but also orthogonal. Since this is true, the equation changes to:
$$ D = C^{T}AC$$✅ **QUESTION:** Why do we care if $C$ is orthogonal? What advantages does the above equation give us?
Put your answer to the above question here.
Please fill out the form that appears when you run the code below. You must completely fill this out in order to receive credit for the assignment!
If you have trouble with the embedded form, please make sure you log on with your MSU google account at googleapps.msu.edu and then click on the direct link above.
✅ **Assignment-Specific QUESTION:** Why do we care if $C$ is orthogonal? What advantages does the above equation give us?
Put your answer to the above question here
✅ **QUESTION:** Summarize what you did in this assignment.
Put your answer to the above question here
✅ **QUESTION:** What questions do you have, if any, about any of the topics discussed in this assignment after working through the jupyter notebook?
Put your answer to the above question here
✅ **QUESTION:** How well do you feel this assignment helped you to achieve a better understanding of the above mentioned topic(s)?
Put your answer to the above question here
✅ **QUESTION:** What was the most challenging part of this assignment for you?
Put your answer to the above question here
✅ **QUESTION:** What was the least challenging part of this assignment for you?
Put your answer to the above question here
✅ **QUESTION:** What kind of additional questions or support, if any, do you feel you need to have a better understanding of the content in this assignment?
Put your answer to the above question here
✅ **QUESTION:** Do you have any further questions or comments about this material, or anything else that's going on in class?
Put your answer to the above question here
✅ **QUESTION:** Approximately how long did this pre-class assignment take?
Put your answer to the above question here
from IPython.display import HTML
HTML(
"""
<iframe
src="https://cmse.msu.edu/cmse314-pc-survey"
width="100%"
height="1000px"
frameborder="0"
marginheight="0"
marginwidth="0">
Loading...
</iframe>
"""
)
To get credits for this assignment, you must fill out and submit the above survey form on or before the assignment due date.
Written by Dirk Colbry, Michigan State University
This work is licensed under a Creative Commons Attribution-NonCommercial 4.0 International License.