(1) Show that \(A^TA != AA^T\) in general. (Proof and demonstration.)
Here lets prove the above condition with examples and function
output <- function(A) {
LHS <- t(A) %*% A
RHS <- A %*% t(A)
print(LHS)
print(RHS)
return (LHS==RHS)
}
# 2x2 matrix
output(matrix(c(1,3,2,1),2))
## [,1] [,2]
## [1,] 10 5
## [2,] 5 5
## [,1] [,2]
## [1,] 5 5
## [2,] 5 10
## [,1] [,2]
## [1,] FALSE TRUE
## [2,] TRUE FALSE
# 3x3 matrix
output(matrix(c(1,2,3,1,1,1,2,0,1),nrow=3))
## [,1] [,2] [,3]
## [1,] 14 6 5
## [2,] 6 3 3
## [3,] 5 3 5
## [,1] [,2] [,3]
## [1,] 6 3 6
## [2,] 3 5 7
## [3,] 6 7 11
## [,1] [,2] [,3]
## [1,] FALSE FALSE FALSE
## [2,] FALSE FALSE FALSE
## [3,] FALSE FALSE FALSE
#4x4
output(matrix(c(1,2,1,3,4,1,2,3,1,1,5,7,2,5,6,2),nrow=4))
## [,1] [,2] [,3] [,4]
## [1,] 15 17 29 24
## [2,] 17 30 36 31
## [3,] 29 36 76 51
## [4,] 24 31 51 69
## [,1] [,2] [,3] [,4]
## [1,] 22 17 26 26
## [2,] 17 31 39 26
## [3,] 26 39 66 56
## [4,] 26 26 56 71
## [,1] [,2] [,3] [,4]
## [1,] FALSE TRUE FALSE FALSE
## [2,] TRUE FALSE FALSE FALSE
## [3,] FALSE FALSE FALSE FALSE
## [4,] FALSE FALSE FALSE FALSE
Above output shows that \(A^TA != AA^T\). Generally \(A.B != B.A\)
(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 matrixIis an example of such a matrix).
But the above mentioned case is not true in all the places. Below are some exceptional scenarios.
# 3x3 Identity matrix
output(matrix(c(1,0,0,0,1,0,0,0,1),nrow=3))
## [,1] [,2] [,3]
## [1,] 1 0 0
## [2,] 0 1 0
## [3,] 0 0 1
## [,1] [,2] [,3]
## [1,] 1 0 0
## [2,] 0 1 0
## [3,] 0 0 1
## [,1] [,2] [,3]
## [1,] TRUE TRUE TRUE
## [2,] TRUE TRUE TRUE
## [3,] TRUE TRUE TRUE
# 2x2 Symmetric matrix
output(matrix(c(1,2,2,7),nrow=2,ncol=2))
## [,1] [,2]
## [1,] 5 16
## [2,] 16 53
## [,1] [,2]
## [1,] 5 16
## [2,] 16 53
## [,1] [,2]
## [1,] TRUE TRUE
## [2,] TRUE TRUE
# 3x3 Symmetric matrix
output(matrix(c(1,4,5,4,2,6,5,6,3),nrow=3,ncol=3))
## [,1] [,2] [,3]
## [1,] 42 42 44
## [2,] 42 56 50
## [3,] 44 50 70
## [,1] [,2] [,3]
## [1,] 42 42 44
## [2,] 42 56 50
## [3,] 44 50 70
## [,1] [,2] [,3]
## [1,] TRUE TRUE TRUE
## [2,] TRUE TRUE TRUE
## [3,] TRUE TRUE 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 ights 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 fight 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_output <- function(A) {
L <- diag(nrow =dim(A)[1])
for(i in (1:dim(A)[1])) {
for(j in (1:dim(A)[1])) {
if(j<i) {
Eliminate <- diag(nrow =dim(A)[1])
lower <- diag(nrow =dim(A)[1])
if(A[i,j]>0) {
Eliminate[i,j] <- -1*A[i,j]
}
else {Eliminate[i,j] <- A[i,j]
}
A <- Eliminate %*% A
L <- L %*% solve(Eliminate)
}
}
}
print("Lower Matrix")
print(L)
print("Upper Matrix")
print(A)
print("Multiply (L*U)")
print(L %*% A)
#remove(L)
}
factor_output(matrix(c(1,2,3,1,1,1,2,0,1),nrow=3,ncol=3))
## [1] "Lower Matrix"
## [,1] [,2] [,3]
## [1,] 1 0 0
## [2,] 2 1 0
## [3,] 3 2 1
## [1] "Upper Matrix"
## [,1] [,2] [,3]
## [1,] 1 1 2
## [2,] 0 -1 -4
## [3,] 0 0 3
## [1] "Multiply (L*U)"
## [,1] [,2] [,3]
## [1,] 1 1 2
## [2,] 2 1 0
## [3,] 3 1 1