Source files: [https://github.com/djlofland/DATA605_S2020/tree/master/]

Problem Set 1

  1. Show that \(A^{T}A \ne AA^{T}\) in general:

\[\text{Given: }A = \left[\begin{array}\\ a & b\\ c & d\\\end{array}\right]\ \text{then}\ A^{T} = \left[\begin{array}\\ a & c\\ b & d\\\end{array}\right]\\ \text{show} \ A^{T}A \ne AA^{T}\\ \left[\begin{array}\\ a & c\\ b & d\\\end{array}\right] \left[\begin{array}\\ a & b\\ c & d\\\end{array}\right] \ne \left[\begin{array}\\ a & b\\ c & d\\\end{array}\right] \left[\begin{array}\\ a & c\\ b & d\\\end{array}\right]\\ \left[\begin{array}\\ aa+cc & ca+cd\\ ba+dc & bb+dd\\\end{array}\right] \ne \left[\begin{array}\\ aa+bb & ac+bd\\ ca+db & cc+dd\\\end{array}\right]\\ (aa+cc) \ne (aa+bb), (ca+cd) \ne (ac+bd), (ba+dc) \ne (ca+db), (bb+dd) \ne (cc+dd)\\ \therefore \\ A^{T}A \ne AA^{T} \]

  1. For a special type of square matrix \(A\), we get \(A^{T}A = AA^{T}\) under what conditions could this be true?

\[\text{Given: }A = \left[\begin{array}\\ a & b & c\\ d & e & f\\ g & h & i \end{array}\right]\ then\ A^{T} = \left[\begin{array}\\ a & d & g\\ b & e & h\\ c & f & i \end{array}\right]\]

\(A^{T}A = AA^{T}\) would hold true if \(b=d, c=g, f=h\) since \(A^{T}\) would then equal \(A\) and the problem simplifies to \(AA = AA\)

Problem Set 2

Matrix factorization is a very important problem. There are supercomputers built just to do matrix factorizations. 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. Please submit your response in an R Markdown document using our class naming convention, E.g. LFulton_Assignment2_PS2.png

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. If you doing the entire assignment in R, then please submit only one markdown document for both the problems.

factor_matrix <- function(A) {
  size <- nrow(A)
  max <- size - 1
  
  # Build our base L matrix
  L <- matrix(0, nrow=size, ncol=size)
  
  for (i in 1:size) {
    L[i,i] = 1L
  }
  
  # Copy A into U - we will be decompsing U as we go and keep our orig A
  U <- matrix(0, nrow=size, ncol=size)
  for (r in 1:size) {
    for (c in 1:size) {
      U[r,c] <- A[r,c]
    }
  }
  
  for (c in 1:max) {
    base_row <- c
    next_row <- c+1
    
    for (r in next_row:size) {
      # print(c(c, r))
      
      L[r, c] = U[r, c] / U[base_row, c]
      U[r,] = U[r,] - U[base_row,] * L[r, c]
    }
  }
  
  U <- round(U, 5)
  L <- round(L, 5)
  
  return(list("A"=A, "U"=U, "L"=L))
}

matrix_size <- 6
A <- matrix(sample(-100:100, matrix_size^2), byrow=T, nrow=matrix_size, ncol=matrix_size)
result <- factor_matrix(A)

print(result)
## $A
##      [,1] [,2] [,3] [,4] [,5] [,6]
## [1,]   35   44  -22  -57   61  -46
## [2,]  -68  -95  -81  -11  -75   90
## [3,]   92   40  -20   49  -91  -70
## [4,]  -21   55  -56   46  -17   -5
## [5,]   82  -87  -48   19   29   16
## [6,]   66  100   37   79 -100   34
## 
## $U
##      [,1]     [,2]      [,3]      [,4]       [,5]      [,6]
## [1,]   35 44.00000  -22.0000  -57.0000   61.00000 -46.00000
## [2,]    0 -9.51429 -123.7429 -121.7429   43.51429   0.62857
## [3,]    0  0.00000 1021.8258 1166.9219 -597.36637  45.91592
## [4,]    0  0.00000    0.0000  258.2678 -267.48267  23.45966
## [5,]    0  0.00000    0.0000    0.0000  212.91718  21.99141
## [6,]    0  0.00000    0.0000    0.0000    0.00000 125.00501
## 
## $L
##          [,1]     [,2]     [,3]     [,4]     [,5] [,6]
## [1,]  1.00000  0.00000  0.00000  0.00000  0.00000    0
## [2,] -1.94286  1.00000  0.00000  0.00000  0.00000    0
## [3,]  2.62857  7.95195  1.00000  0.00000  0.00000    0
## [4,] -0.60000 -8.55556 -1.10380  1.00000  0.00000    0
## [5,]  2.34286 19.97898  2.42292 -0.93900  1.00000    0
## [6,]  1.88571 -1.78979 -0.13993  0.51065 -0.39522    1