#Installing pracma package
install.packages("pracma", dependencies = TRUE, repos = "http://mirrors.nics.utk.edu/cran/")
## Installing package into 'C:/Users/Lelan/Documents/R/win-library/3.4'
## (as 'lib' is unspecified)
## package 'pracma' successfully unpacked and MD5 sums checked
##
## The downloaded binary packages are in
## C:\Users\Lelan\AppData\Local\Temp\RtmpmW4Epq\downloaded_packages
library(pracma)
Find the eigenvalues, eigenspaces, algebraic and geometric multiplicities for
\[ A= \left[ {\begin{array}{ccc} 1 & -1 & 1\\ -1 & 1 & -1\\ 1 & -1 & 1\\ \end{array} } \right] \]
#Create matrix
A <- matrix(c(1,-1,1,-1,1,-1,1,-1,1),nrow=3)
A
## [,1] [,2] [,3]
## [1,] 1 -1 1
## [2,] -1 1 -1
## [3,] 1 -1 1
#Use eigen function on matrix
e <- eigen(A)
#Get eigenvalues from named list returned by eigen function
#I am rounding to avoid the exponentially tiny scientific numbers R sometimes creates
round(e$values, digits=14)
## [1] 3 0 0
#Get eigenvectors from named list returned by eigen function
e$vectors
## [,1] [,2] [,3]
## [1,] 0.5773503 -0.8164966 0.0000000
## [2,] -0.5773503 -0.4082483 0.7071068
## [3,] 0.5773503 0.4082483 0.7071068
#Find characteristic polynomial of A
charpoly(A)
## [1] 1 -3 0 0
The characteristic polynomial of the matrix is \(p_{A}(x) = x^3 -3x^2 + 0x + 0\), or \(x^2(x-3)\). Therefore, the algebraic multiplicy of \(\lambda = 0\) is 2 and the algebraic multiplicity of \(\lambda = 3\) is 1.
To find geometric multiplicity for \(\lambda = 3\), compute A - \(\lambda I\) for \(\lambda = 3\):
#Matrix A minus 3 times the identity matrix
L3 <- A - 3*diag(3)
#Row reduce the resulting matrix
RL3 <- rref(L3)
RL3
## [,1] [,2] [,3]
## [1,] 1 0 -1
## [2,] 0 1 1
## [3,] 0 0 0
Because the size of the matrix is 3, and the number of pivots in RL3 is 2, the geometric multiplicity of \(\lambda = 3\) is 1.
To find geometric multiplicity for \(\lambda = 0\), compute A - \(\lambda I\) for \(\lambda = 0\), which is the same as A:
#Matrix A minus 0 times the identity matrix is A
#Row reduce the resulting matrix, which is A
RL0 <- rref(A)
RL0
## [,1] [,2] [,3]
## [1,] 1 -1 1
## [2,] 0 0 0
## [3,] 0 0 0
Because the size of the matrix is 3, and the number of pivots in the RL0 is 1, the geometric multiplicity of \(\lambda = 0\) is 2.