1. Show that ATA≠AAT in general. (Proof and demonstration.)
#A<-matrix(1:4, nrow = 2, ncol = 2) #fills column by column
A<- matrix(1:4, nrow=2, byrow=TRUE)
A
##      [,1] [,2]
## [1,]    1    2
## [2,]    3    4
tr<-(t(A))
print(tr)
##      [,1] [,2]
## [1,]    1    3
## [2,]    2    4
a<-(A %*% tr)

b<-(tr %*% A)

print(b)
##      [,1] [,2]
## [1,]   10   14
## [2,]   14   20
identical(a,b)
## [1] FALSE
#If the matrix is equal, all.equal returns 'TRUE'
all.equal(a,b)
## [1] "Mean relative difference: 0.3076923"
  1. For a special type of square matrix A, we get AT A = AAT, this special type of matrix is a symmetric matrix. A symmetric matrix is a matrix that is equal to it's transpose and is a square.

How to check Whether a Matrix is Symmetric or Not? 1. Find the transpose of the matrix. 2. Compare transpose of the matrix to the original matrix. 3. If both matrixes are equal, then the matrix is symmetric.

B<-cbind(c(2,4),c(4,2))
B
##      [,1] [,2]
## [1,]    2    4
## [2,]    4    2
print(t(B))
##      [,1] [,2]
## [1,]    2    4
## [2,]    4    2
identical(B,t(B))
## [1] TRUE

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.

trix<- rbind(c(1,4,-3),c(-2,8,5), c(3,4,7))
  
  r <- nrow(A)
  print(r)
## [1] 2
  U <- A
  L <- diag(r)  
  print(L)
##      [,1] [,2]
## [1,]    1    0
## [2,]    0    1
  for (x in c(1:r)){
    #print(paste('x outer loop', x))
    for(y in c(2:r)){
      #print(paste('y outer loop',y))
      if(y > x){
          row <- U[x,]
          #print(U[x,])
          #print(paste("x ",x))
          #print(paste("y", y))
          #print(paste("(U[x,]) ",(U[x,])))
          #Switching x and y allows us to get the opposite of multipliers.
          multiplier <- U[y, x] / row[x]
          print(paste("(U[x,y]) ",(U[x,y])))
       
          #print(paste("(U[y,x]) ",(U[y, x])))
          #print(paste("multiplier ",multiplier))
        
          #print(paste("row[x] ",row[x]))
          #print('-------------')
          U[y,] <- U[y,] - (multiplier * row)
          L[y,x] <- multiplier
      }
    }
  }
## [1] "(U[x,y])  2"
  return(list(L=L, U=U))
## $L
##      [,1] [,2]
## [1,]    1    0
## [2,]    3    1
## 
## $U
##      [,1] [,2]
## [1,]    1    2
## [2,]    0   -2
# 1, 1    2, 1   3,1
# 2, 2    3,2
# 3, 3

LaTeX failed to compile on my machine (I think it has to do with the version on my Mac), but I will try to resubmit it with it working! I hope the professor will understand.

References: https://www.vedantu.com/maths/symmetric-and-skew-symmetric-matrix, https://www.youtube.com/watch?v=UlWcofkUDDU