C12: For the matrix, A, the characteristic polynomial (CP) is \((x+2)(x-2^2)(x-4)\) Find the eigenvalues and corresponding eigenspaces of A.

library('pracma')
A = matrix(c(0,-2,-2,-2,4,6,8,8,-1,-1,-1,-3,1,1,-1,1),nrow = 4, ncol = 4)
A
##      [,1] [,2] [,3] [,4]
## [1,]    0    4   -1    1
## [2,]   -2    6   -1    1
## [3,]   -2    8   -1   -1
## [4,]   -2    8   -3    1

Multiplying the characteristic polynomial by hand produces \(x^3-6x^2+32\)

# Finding the roots of CP gives eigenvalues
# Turn the simplfied CP into a vector
# The vector will be created in ascending order of the coefficients' respective powers.

t <- c(32, 0,-6, 1) # This translates to x^3-6x^2-32
eigenvalues <- polyroot(t)
eigenvalues
## [1] -2+0i  4-0i  4+0i

Eigenspace is equal to the set of vectors that satisafy the null space

# Denote the discovered eigenvalues as E(1,2,3)
# Eigenspace is found by subtracting the matrix A from the product of each eigenvalue multiplied by the ID matrix
E1 <- -2
E2 <- 4
E3 <- 4

E1_I <- E1 * diag(4)
Eigenspace1 <- E1_I - A
Eigenspace1
##      [,1] [,2] [,3] [,4]
## [1,]   -2   -4    1   -1
## [2,]    2   -8    1   -1
## [3,]    2   -8   -1    1
## [4,]    2   -8    3   -3
E2_I <- E2 * diag(4)
Eigenspace2 <- E2_I - A
Eigenspace2
##      [,1] [,2] [,3] [,4]
## [1,]    4   -4    1   -1
## [2,]    2   -2    1   -1
## [3,]    2   -8    5    1
## [4,]    2   -8    3    3
E3_I <- E3 * diag(4)
Eigenspace3 <- E3_I - A
Eigenspace3
##      [,1] [,2] [,3] [,4]
## [1,]    4   -4    1   -1
## [2,]    2   -2    1   -1
## [3,]    2   -8    5    1
## [4,]    2   -8    3    3

We can also reduce each eigenspace into row-reduced echelon form in order to see which eigenspace corresponds to the eigenvalue of the nullspace

reduced_ES1 <- rref(Eigenspace1)
reduced_ES2 <- rref(Eigenspace2)
reduced_ES3 <- rref(Eigenspace3)

reduced_ES1
##      [,1] [,2] [,3] [,4]
## [1,]    1    0    0    0
## [2,]    0    1    0    0
## [3,]    0    0    1   -1
## [4,]    0    0    0    0
reduced_ES2
##      [,1] [,2] [,3] [,4]
## [1,]    1    0    0   -1
## [2,]    0    1    0   -1
## [3,]    0    0    1   -1
## [4,]    0    0    0    0
reduced_ES3
##      [,1] [,2] [,3] [,4]
## [1,]    1    0    0   -1
## [2,]    0    1    0   -1
## [3,]    0    0    1   -1
## [4,]    0    0    0    0