18.2 Computing eigenvalues and eigenvectors
Let’s understand a little on solving det to determine the eigenvalues.
First consider the 2 by 2 matrix:
\begin{equation*} A = \begin{pmatrix} a & b \\ c & d \end{pmatrix}, \end{equation*}
So then A - \lambda I is the matrix:
\begin{equation*} A - \lambda I=\begin{pmatrix} a - \lambda & b \\ c & d-\lambda \end{pmatrix} \end{equation*}
The determinant of a 2 by 2 matrix is the product of the diagonal entries (for A - \lambda I they are (a-\lambda)\cdot (d-\lambda)) less the product of the off-diagonal entries (in this case bc). So \det(A-\lambda I)=0 is the equation (a-\lambda)(d-\lambda)-bc=0. When we multiply this equation out we obtain a quadratic equation to solve (for \lambda - see Exercise 18.7). The equation \det(A - \lambda I)=0 even has a special name - it is called the characteristic equation. (We will find out why later.)
Solution. The matrix A-\lambda I is: \displaystyle A-\lambda I = \begin{pmatrix} -1-\lambda & 1 \\ 0 & 3-\lambda \end{pmatrix}. So we have:
\begin{equation} \det(A-\lambda I) = (-1-\lambda)(3-\lambda) - 0 = 0 \end{equation}
Solving the equation (-1-\lambda)(3-\lambda)=0 yields two eigenvalues: \lambda = -1 or \lambda = 3.Solution. So if we consider the right hand side of A \vec{v} - \lambda \vec{v} =\vec{0} we have:
\begin{equation*} ( A \vec{v} - \lambda \vec{v} ) = \begin{pmatrix} -x +y - \lambda x \\ 3y - \lambda y \end{pmatrix}. \end{equation*}.
Examining this setup gives us two equations to work with: - x + y - \lambda x = 0 and 3y-\lambda y =0. We will need to analyze them for each of our eigenvalues.
- Case 1: \lambda = -1. In the first equation we have -x+y+x =0, which just yields y=0. For the second equation we also have 3y+y =0, so that tells us again that y=0. Notice how we solved for y, but we didn’t uniquely determine x. While this seems a little unsatisfying, that is ok. The form of this particular straight line solution is \displaystyle s_{1}(t)=e^{-t} \begin{pmatrix} x \\ 0 \end{pmatrix}, where x is a free variable.
- Case 2: \lambda = 3. For the second equation we have 3y - 3y=0, which is always true. However in the first equation we have - x + y - 3x = 0, or y = 4x. In this case, x can be anything as well, but this condition means that y will have to be 4 times that value. Hence, this particular straight line solution is \displaystyle s_{2}(t)=e^{3t} \begin{pmatrix} x \\ 4x \end{pmatrix}.
Once we have computed the eigenvalues and eigenvectors, we are now ready to express the most general solution for a system of differential equations. For a two-dimensional system of linear differential equations (\displaystyle \frac{d}{dt} \vec{x} = A \vec{x}, the most general solution is \vec{x}(t) = c_{1} e^{\lambda_{1}t} \vec{v}_{1} + c_{2} e^{\lambda_{2}t} \vec{v}_{2}
Solution. Since we have already computed the eigenvalues and eigenvectors, our most general solution is:
\begin{equation*} \vec{x} = c_{1} e^{- t} \begin{pmatrix} 1 \\ 0 \end{pmatrix} + c_{2} e^{3t} \begin{pmatrix} 1 \\ 4 \end{pmatrix} \end{equation*}
18.2.1 Eigenvalues computed with demodelr
While computing eigenvalues and eigenvectors is a good algebraic exercise, we can also program this in R
using the function eigenvalues
from the demodelr
package. The syntax works where \displaystyle A = \begin{pmatrix} a & b \\ c & d \end{pmatrix} is entered in as eigenvalues(a,b,c,d,matrix_rows)
where matrix_rows
is the number of rows6. What gets returned from the function will be the eigenvalues and eigenvectors for any square matrix.
# For a two dimensional equation the code assumes the default is a 2 by 2 matrix, .
eigenvalues(matrix_entries = c(-1, 1, 0, 3),
matrix_rows = 2)
## eigen() decomposition
## $values
## [1] 3 -1
##
## $vectors
## X1 X2
## 1 0.2425356 1
## 2 0.9701425 0
# This is equivalent because we have a two dimensional equation:
#eigenvalues(c(-1, 1, 0, 3))
Notice that the eigenvalues and the eigenvectors get returned. How you read the output for the eigenvector is that X1
is the eigenvector associated with the first eigenvalue (\lambda = 3) and X2
is the eigenvector associated with the second eigenvalue (\lambda = -1). The eigenvector associated with \lambda=3 is a little different from what we computed - R
will normalize the vector, which means that its total length will be one.7 However upon closer inspection in our solution we found that the second component was 4 times the first for the eigenvector, which is indeed the case.
If you have a 2 by 2 matrix, you can leave out
matrix_rows
(so justeigenvalues(a,b,c,d)
) as the default is a 2 by 2 matrix.↩︎The length of a vector \vec{v} is denoted as ||\vec{v}|| and is computed the following way: ||\vec{v}||=\sqrt{v_{1}^{2}+v_{2}^{2}+...+v_{n}^{2}}. We normalize a vector to a length of 1 by dividing each component by its length.↩︎