1) Prove for that in general: \[A^TA \neq AA^T \]
Let the the transpose of A be equal to B for the sake of clarity.
\[ A^T = B\] So I am to prove \[ BA \neq AB \]
\[ AB = \left(\begin{array}{ccc} a_{11} & a_{12}\\ a_{21} & a_{22} \\ \end{array}\right) * \left(\begin{array}{cc} b_{11} & b_{12}\\ b_{21} & b_{22} \\ \end{array}\right) = \left(\begin{array}{ccc} a_{11}b_{11}+a_{12}b_{21} & a_{11}b_{12}+a_{12}b_{22}\\ a_{21}b_{11}+a_{22}b_{21} & a_{21}b_{12}+a_{22}b_{22} \\ \end{array}\right) \] \[ BA = \left(\begin{array}{cc} b_{11} & b_{12}\\ b_{21} & b_{22} \\ \end{array}\right)* \left(\begin{array}{ccc} a_{11} & a_{12}\\ a_{21} & a_{22} \\ \end{array}\right) = \left(\begin{array}{ccc} b_{11}a_{11}+b_{12}a_{21} & b_{11}a_{12}+b_{12}a_{22}\\ b_{21}a_{11}+b_{22}a_{21} & b_{21}a_{12}+b_{22}a_{22} \\ \end{array}\right) \]
There are special cases, such as the zero matrix; or any symmetrical matrix in such that \[A^T = A\] in which \[A^TA = AA^T \]
Question 2 : Write an R function to factorize a square matrix A into LDU
LU = function(A){
#Check if square
if(dim(A)[1]!=dim(A)[2]){
return('Not a square matrix')
}
# Gather matrix dimensions
rows = columns = dim(A)[1]
# A = LDU
# L = Lower triangle matrix
# D = Diagonal matrix
# U = Upper triangle matrix
U = A
L = D = diag(rows)
#Column Loop
for (j in 1:(columns-1)){
#row loop
for (i in (j+1):rows){
#elimination
L[i,j] = (U[i,j]/U[j,j])
U[i,] = U[i,]-(U[j,]*L[i,j])
}
}
#transfer the middle diagonal from upper triangular matrix
diag(D) = diag(U)
for (l in 1:rows){
U[l,] = U[l,]/U[l,l]
}
LDU = list("Lower"=L,"Diagonal"=D,"Upper"=U)
return(LDU)
}
#The matrix I used in assignment 1
A = matrix(c(1,2,-1,1,-1,-2,3,5,4),nrow=3,ncol = 3)
LU(A)
## $Lower
## [,1] [,2] [,3]
## [1,] 1 0.0000000 0
## [2,] 2 1.0000000 0
## [3,] -1 0.3333333 1
##
## $Diagonal
## [,1] [,2] [,3]
## [1,] 1 0 0.000000
## [2,] 0 -3 0.000000
## [3,] 0 0 7.333333
##
## $Upper
## [,1] [,2] [,3]
## [1,] 1 1 3.0000000
## [2,] 0 1 0.3333333
## [3,] 0 0 1.0000000
Sources [https://www.youtube.com/watch?v=rhNKncraJMk http://rstudio-pubs-static.s3.amazonaws.com/223289_e12b9066dfa24a38b354deacf591f118.html] http://54.225.166.221/simonnyc/107423