Eigenvalues and eigenvectors: Eigenvalues and eigenvectors in R
Eigenvalues and eigenvectors
You can compute eigenvalues and eigenvectors in R with the function eigen
. Below we give two examples: \[A=\matrix{1 & -3 & 3 \\ 3 & -5 & 3\\ 6 & -6 & 4}\quad\text{and}\quad \matrix{-1 & 1 & -1 \\ -7 & 5 & -1\\ 6 & -6 & -2}\] These two matrices have the same characteristic polynomial \((t+2)^2(t - 4)\), but \(A\) is diagonalisable while \(B\) is not. This is because the eigenspace for eigenvalue \(-2\) of matrix \(A\) has two eigenvectors which is not a multiple of each other, while this is not true in the case of matrix \(B\).
> A <- matrix(c(1, -3, 3, 3, -5, 3, 6, -6, 4), nrow=3, byrow=TRUE); A [,1] [,2] [,3] [1,] 1 -3 3 [2,] 3 -5 3 [3,] 6 -6 4 > B <- matrix(c(-3, 1, -1, -7, 5, -1, -6, 6, -2), nrow=3, byrow=TRUE); B [,1] [,2] [,3] [1,] -3 1 -1 [2,] -7 5 -1 [3,] -6 6 -2 > evA <- eigen(A) # eigenvalue problem of A solved > evA$values # eigenvalues of A [1] 4 -2 -2 > evA$vectors # column vectors are eigenvectors of A [,1] [,2] [,3] [1,] -0.4082483 0.2440012 -0.4070223 [2,] -0.4082483 -0.4162191 -0.4070223 [3,] -0.8164966 -0.6602203 0.0000000
> D <- diag(evA$values); V <- evA$vector
> # column vectors of V ar eigenvectors > # diagonal elements of D are eigenvalues
> round(A %*% V - V %*%D, 3) # check
[,1] [,2] [,3] [1,] 0 0 0 [2,] 0 0 0 [3,] 0 0 0
> evB <- eigen(B) # eigenvalue problem of B solved > evB$values # eigenvalues of B [1] 4 -2 -2 > evB$vectors # column vectors are eigenvectors of B [,1] [,2] [,3] [1,] 6.567298e-17 7.071068e-01 -7.071068e-01 [2,] -7.071068e-01 7.071068e-01 -7.071068e-01 [3,] -7.071068e-01 2.257218e-08 2.257218e-08 > round(.Last.value, 3) # rounding of numbers for eease of reading [,1] [,2] [,3] [1,] 0.000 0.707 -0.707 [2,] -0.707 0.707 -0.707 [3,] -0.707 0.000 0.000
In this case you must notice all by yourself that the last two column vectors of \(V\) are in fact multiples of each other and that the eigenspace of \(B\) for eigenvalue \(-2\) is spanned by one eigenvector.
Unlock full access