{Question #1 : Show that AT A ΜΈ= AAT in general. (Proof and demonstration.)

\[\begin{bmatrix} a & b \\ c & d \end{bmatrix}\\ A^T = \begin{bmatrix} a & c \\ b & d \end{bmatrix}^T \\ AA^T = \begin{bmatrix} a & b \\ c & d \end{bmatrix} \begin{bmatrix} a & c \\ b & d \end{bmatrix}^T = \begin{bmatrix} a^2+b^2 & ac+bd \\ ac+bd & c^2+d^2 \end{bmatrix} \\ A^TA = \begin{bmatrix} a & c \\ b & d \end{bmatrix}^T \begin{bmatrix} a & b \\ c & d \end{bmatrix} = \begin{bmatrix} a^2+c^2 & ab+cd \\ ab+cd & b^2+d^2 \end{bmatrix}\\ AA^T \neq A^TA \Rightarrow \begin{bmatrix} a^2+b^2 & ac+bd \\ ac+bd & c^2+d^2 \end{bmatrix} \neq \begin{bmatrix} a^2+c^2 & ab+cd \\ ab+cd & b^2+d^2 \end{bmatrix}\\\]

\[ \text {Question #2: For a special type of square matrix A, we get} A^TA = AA^T\\ \text{Under what conditions could this be true? (Hint: The Identity matrix I is an example of such a matrix).} \\{For} A^TA = AA^T \text{the matrix must be symmetric} \]

\[\begin{bmatrix} 1 & 2 & 3 \\ 2 & 4 & 5 \\ 3 & 5 & 6 \end{bmatrix} \] Showing that \(A^TA\) and \(AA^T\) to demonstrate that they are equal: \[ A^TA = \begin{bmatrix} 1 & 2 & 3 \\ 2 & 4 & 5 \\ 3 & 5 & 6 \end{bmatrix}^T \begin{bmatrix} 1 & 2 & 3 \\ 2 & 4 & 5 \\ 3 & 5 & 6 \end{bmatrix} = \begin{bmatrix} 14 & 26 & 33 \\ 26 & 45 & 56 \\ 33 & 56 & 70 \end{bmatrix}\] \[ AA^T = \begin{bmatrix} 1 & 2 & 3 \\ 2 & 4 & 5 \\ 3 & 5 & 6 \end{bmatrix} \begin{bmatrix} 1 & 2 & 3 \\ 2 & 4 & 5 \\ 3 & 5 & 6 \end{bmatrix}^T = \begin{bmatrix} 14 & 26 & 33 \\ 26 & 45 & 56 \\ 33 & 56 & 70 \end{bmatrix} \]
lu_factorize <- function(A) {
  n <- nrow(A)
  L <- diag(n)      # Initializing L as an identity matrix
  U <- matrix(0, n, n)  # Initializing U as a zero matrix

  for (k in 1:(n - 1)) {
    # Calculating the factor 
    factor <- A[(k + 1):n, k] / A[k, k]
    A[(k + 1):n, k:n] <- A[(k + 1):n, k:n] - outer(factor, A[k, k:n])
    L[(k + 1):n, k] <- factor
  }

  # using logical indexing to return U ( non zero values)
  U <- A * upper.tri(A)

  # using logical indexing to return L ( non zero values)
  L[lower.tri(L, diag = TRUE)] <- A[lower.tri(A, diag = TRUE)]

  return(list(L = L, U = U))
}