Problem 1

1. Show that \(A^T A \neq AA^T\) in general. (Proof and demonstration.)

Indirect Proof:


2. For a special type of square matrix A, we get \(A^T A = AA^T\) . Under what conditions could this be true? (Hint: The Identity matrix I is an example of such a matrix).

For \(A^T A = AA^T\) to be true, under special condition is for A to be orthogonal matrix.

# Define a orthogonal matrix A
A <- matrix(c(0, -1, 1, 0), nrow = 2)
AtA <- t(A) %*% A
AAt <- A %*% t(A)
isEqual <- identical(AtA, AAt)
print(paste("Is A^T * A equal to A * A^T?:", isEqual))
## [1] "Is A^T * A equal to A * A^T?: TRUE"

Problem 2

Matrix factorization is a very important problem. There are supercomputers built just to do matrix factorization. Every second you are on an airplane, matrices are being factorized. Radars that track flights use a technique called Kalman filtering. At the heart of Kalman Filtering is a Matrix Factorization operation. Kalman Filters are solving linear systems of equations when they track your flight using radars.

Write an R function to factorize a square matrix A into LU or LDU, whichever you prefer. You don’t have to worry about permuting rows of A and you can assume that A is less than 5x5, if you need to hard-code any variables in your code.

# LU Factorization Function
# Doolittle algorithm
lu_factorization <- function(A) {
  n <- nrow(A)
  L <- diag(1, n)
  U <- A
  
  for (i in 1:(n-1)) {
    for (j in (i+1):n) {
      L[j, i] <- U[j, i] / U[i, i]
      U[j, i:n] <- U[j, i:n] - L[j, i] * U[i, i:n]
    }
  }
  
  return(list(L = L, U = U))
}

# Testing the function
A <- matrix(c(1, 2, 3, 1, 1, 1, 2, 0, 1), nrow = 3)
lu_result <- lu_factorization(A)
lu_result$L
##      [,1] [,2] [,3]
## [1,]    1    0    0
## [2,]    2    1    0
## [3,]    3    2    1
lu_result$U
##      [,1] [,2] [,3]
## [1,]    1    1    2
## [2,]    0   -1   -4
## [3,]    0    0    3