C19. Find the eigenvalues, eigenspaces, algebraic multiplicities and geometric multiplicities for the matrix below. It is possible to do all these computations by hand, and it would be instructive to do so.

Step 1: Eigenvalues

# Defining the matrix
C <- matrix(c(-1, 2, -6, 6), nrow = 2, byrow = TRUE)

# The eigenvalues are obtained by solving the characteristic equation determinant(C - lambda Identity) = 0, where Identity is the Identity matrix
# This leads us to the characteristic polynomial: (-1 -lambda) (-6 - lambda) -(2x - 6) = 0

# Solving this polynomial equation gives us the eigenvalues.

# Computing eigenvalues
eigenvalues <- eigen(C)$values
eigenvalues
## [1] 3 2

Step 2: Finding the eigenspaces and associated multiplicities for each eigenvalue.

#  Eigenspaces, Algebraic Multiplicity, and Geometric Multiplicity: 
# Compute eigenvalues and eigenvectors
eigen_results <- eigen(C)

# Extract eigenvalues and eigenvectors
eigenvalues <- eigen_results$values
eigenvectors <- eigen_results$vectors

# Loop over each eigenvalue
for (i in seq_along(eigenvalues)) {
  eigenvector <- eigenvectors[, i]
  
  # Calculate algebraic multiplicity
  algebraic_multiplicity <- sum(round(eigenvalues, 6) == round(eigenvalues[i], 6))
  
  # Calculate geometric multiplicity
  geometric_multiplicity <- sum(abs(eigenvector) > 1e-6)
  
  cat("\nEigenvalue:", eigenvalues[i])
  cat("\nEigenvector:", eigenvector)
  cat("\nAlgebraic Multiplicity:", algebraic_multiplicity)
  cat("\nGeometric Multiplicity:", geometric_multiplicity, "\n")
}
## 
## Eigenvalue: 3
## Eigenvector: -0.4472136 -0.8944272
## Algebraic Multiplicity: 1
## Geometric Multiplicity: 2 
## 
## Eigenvalue: 2
## Eigenvector: -0.5547002 -0.8320503
## Algebraic Multiplicity: 1
## Geometric Multiplicity: 2

C11 Find the characteristic polynomial of the matrix A

# Install and load the Matrix package (if not already installed)

library(Matrix)
library(MASS)
# Define the matrix A
A <- matrix(c(3, 2, 1, 0, 1, 1, 1, 2, 0), nrow = 3, byrow = TRUE)


# Calculate the characteristic polynomial for A^TA
char_poly_coeff <- eigen(t(A) %*% A)$values

# Print the characteristic polynomial coefficients
cat("Characteristic Polynomial Coefficients:\n")
## Characteristic Polynomial Coefficients:
print(char_poly_coeff)
## [1] 18.5990220  1.5119648  0.8890132