C23 Find the eigenvalues, eigenspaces, algebraic and geometric multiplicities for A = 1 1 1 1
First we define the matrix
A <- matrix(c(1, 1, 1, 1), nrow = 2, byrow = TRUE)
Eigenvalues and Eigenvectors are then calculated
eigen_A <- eigen(A)
print(eigen_A)
## eigen() decomposition
## $values
## [1] 2 0
##
## $vectors
## [,1] [,2]
## [1,] 0.7071068 -0.7071068
## [2,] 0.7071068 0.7071068
Extracting eigenvalues and eigenvectors
lambda <- eigen_A$values
vectors <- eigen_A$vectors
print("Eigenvalues:")
## [1] "Eigenvalues:"
print(lambda)
## [1] 2 0
print("Eigenvectors:")
## [1] "Eigenvectors:"
print(vectors)
## [,1] [,2]
## [1,] 0.7071068 -0.7071068
## [2,] 0.7071068 0.7071068
Creating an empty list to store the eigenvectors that corresponds to each eigenvalue
eigenspaces <- list()
Computing the eigenspaces and geometric multiplicities by iterating through each eigenvalue, extracting the corresponding eigenvectors, and determining the number of similar eigenvalues, hence representing geometric multiplicities.
for (i in 1:length(lambda)) {
eigenspaces[[i]] <- vectors[, i]
geometric_multiplicity <- sum(abs(lambda[i] - lambda) < 1e-10)
print(paste("Eigenvector", i, ":"))
print(eigenspaces[[i]])
print(paste("Geometric multiplicity for eigenvalue", lambda[i], ":", geometric_multiplicity))
print(paste("Eigenspace for eigenvalue", lambda[i], ":"))
print(eigenspaces[[i]])
}
## [1] "Eigenvector 1 :"
## [1] 0.7071068 0.7071068
## [1] "Geometric multiplicity for eigenvalue 2 : 1"
## [1] "Eigenspace for eigenvalue 2 :"
## [1] 0.7071068 0.7071068
## [1] "Eigenvector 2 :"
## [1] -0.7071068 0.7071068
## [1] "Geometric multiplicity for eigenvalue 0 : 1"
## [1] "Eigenspace for eigenvalue 0 :"
## [1] -0.7071068 0.7071068