1. Problem set 1
  1. Show that AT A 6= AAT in general. (Proof and demonstration.) #demonstration
A <- matrix(c(1,2,1,4,0,-1,3,1,-2), nrow=3, byrow=TRUE)
At <- t(A)

Consider matrix A

A
##      [,1] [,2] [,3]
## [1,]    1    2    1
## [2,]    4    0   -1
## [3,]    3    1   -2

Its transpose At

At
##      [,1] [,2] [,3]
## [1,]    1    4    3
## [2,]    2    0    1
## [3,]    1   -1   -2

Multiplying A by its transpose At

A %*% At
##      [,1] [,2] [,3]
## [1,]    6    3    3
## [2,]    3   17   14
## [3,]    3   14   14

Multiplying transposed A by A

At %*% A
##      [,1] [,2] [,3]
## [1,]   26    5   -9
## [2,]    5    5    0
## [3,]   -9    0    6

Check using logical comparison

A %*% At == At %*% A
##       [,1]  [,2]  [,3]
## [1,] FALSE FALSE FALSE
## [2,] FALSE FALSE FALSE
## [3,] FALSE FALSE FALSE
  1. For a special type of square matrix A, we get AT A = AAT . Under what conditions could this be true? (Hint: The Identity matrix I is an example of such a matrix). Please typeset your response using LaTeX mode in RStudio. If you do it in paper, please either scan or take a picture of the work and submit it. Please ensure that your image is legible and that your submissions are named using your first initial, last name, assignment and problem set within the assignment. E.g. LFulton_Assignment2_PS1.png

If a matrix is symmetrical along the diagonal. This is true because a symmetric matrix and its transpose are equal, meaning you are just multiplying a matrix by itself. If a matrix is symmetrical along the diagonal

demonstration

A <- matrix(c(1,3,0,3,1,0,0,0,1), nrow=3, byrow=TRUE)

matrix A

A
##      [,1] [,2] [,3]
## [1,]    1    3    0
## [2,]    3    1    0
## [3,]    0    0    1

its transpose is the same matrix

t(A)
##      [,1] [,2] [,3]
## [1,]    1    3    0
## [2,]    3    1    0
## [3,]    0    0    1
A == t(A)
##      [,1] [,2] [,3]
## [1,] TRUE TRUE TRUE
## [2,] TRUE TRUE TRUE
## [3,] TRUE TRUE TRUE
(A %*% t(A)) == (t(A) %*% A)
##      [,1] [,2] [,3]
## [1,] TRUE TRUE TRUE
## [2,] TRUE TRUE TRUE
## [3,] TRUE TRUE TRUE
  1. 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.
factorize_LU <- function(A) {
  # Check wheter matrix A is square
  if (dim(A)[1]!=dim(A)[2]) {
    return(NA)
  }
  
  U <- A
  n <- dim(A)[1]
  L <- diag(n)
  
  
  if (n==1) {
    return(list(L,U))
  }
  
  
  for(i in 2:n) {
    for(j in 1:(i-1)) {
      multiplier <- -U[i,j] / U[j,j]
      U[i, ] <- multiplier * U[j, ] + U[i, ]
      L[i,j] <- -multiplier
    }
  }
  return(list(L,U))
}

Demonstration

A <- matrix(c(2,1,1,1,1,3,7,3,4), nrow=3, byrow=TRUE)
LU <- factorize_LU(A)
L<-LU[[1]]  
U<-LU[[2]]

A
##      [,1] [,2] [,3]
## [1,]    2    1    1
## [2,]    1    1    3
## [3,]    7    3    4
L
##      [,1] [,2] [,3]
## [1,]  1.0    0    0
## [2,]  0.5    1    0
## [3,]  3.5   -1    1
U
##      [,1] [,2] [,3]
## [1,]    2  1.0  1.0
## [2,]    0  0.5  2.5
## [3,]    0  0.0  3.0
A == L %*% U
##      [,1] [,2] [,3]
## [1,] TRUE TRUE TRUE
## [2,] TRUE TRUE TRUE
## [3,] TRUE TRUE TRUE

Example 2

A <- matrix(c(1,3,4,7), nrow=2, byrow=TRUE)
LU <- factorize_LU(A)
L<-LU[[1]]  
U<-LU[[2]]

A
##      [,1] [,2]
## [1,]    1    3
## [2,]    4    7
L
##      [,1] [,2]
## [1,]    1    0
## [2,]    4    1
U
##      [,1] [,2]
## [1,]    1    3
## [2,]    0   -5
A == L %*% U
##      [,1] [,2]
## [1,] TRUE TRUE
## [2,] TRUE TRUE