Using an example of a 2x2 matrix and it’s transpose we can see that multiplying them together will not give the same result regardless of matrix and transpose order.
\[\mathbf{A} = \left[\begin{array} {rrr} 1 & 2 \\ 3 & 4 \\ \end{array}\right] \] \[\mathbf{A^T} = \left[\begin{array} {rrr} 1 & 3 \\ 2 & 4 \\ \end{array}\right] \] \[\mathbf{AA^T} = \left[\begin{array} {rrr} (1*1)+(2*2) & (1*3)+(2*4) \\ (3*1)+(4*2) & (3*3)+(4*4) \\ \end{array}\right] \]
\[\mathbf{A^TA} = \left[\begin{array} {rrr} (1*1)+(3*3) & (1*2)+(3*4) \\ (2*1)+(4*3) & (2*2)+(4*4) \\ \end{array}\right] \]
\[(1*1)+(2*2) \neq (1*1)+(3*3)\]
Using R we get the same result using the t function.
E <- matrix(c(1,3,2,4), nrow=2, ncol=2)
E## [,1] [,2]
## [1,] 1 2
## [2,] 3 4
t(E)## [,1] [,2]
## [1,] 1 3
## [2,] 2 4
t(E) %*% E## [,1] [,2]
## [1,] 10 14
## [2,] 14 20
E %*% t(E)## [,1] [,2]
## [1,] 5 11
## [2,] 11 25
A <- matrix(c(3,2,2,-1,5,0,4,1,6), nrow=3, ncol=3)
A## [,1] [,2] [,3]
## [1,] 3 -1 4
## [2,] 2 5 1
## [3,] 2 0 6
t(A)## [,1] [,2] [,3]
## [1,] 3 2 2
## [2,] -1 5 0
## [3,] 4 1 6
t(A)%*%A## [,1] [,2] [,3]
## [1,] 17 7 26
## [2,] 7 26 1
## [3,] 26 1 53
A%*%t(A)## [,1] [,2] [,3]
## [1,] 26 5 30
## [2,] 5 30 10
## [3,] 30 10 40
Since the transpose will equal the orginal matrix, symmetric matricies will have the transpose x matrix = matrix x transpose. Example:
C <- matrix(c(1,0,3,0,2,5,3,5,3), nrow=3, ncol=3)
C## [,1] [,2] [,3]
## [1,] 1 0 3
## [2,] 0 2 5
## [3,] 3 5 3
t(C)## [,1] [,2] [,3]
## [1,] 1 0 3
## [2,] 0 2 5
## [3,] 3 5 3
C%*%t(C)## [,1] [,2] [,3]
## [1,] 10 15 12
## [2,] 15 29 25
## [3,] 12 25 43
t(C)%*%C## [,1] [,2] [,3]
## [1,] 10 15 12
## [2,] 15 29 25
## [3,] 12 25 43
Use the built function to see that that LDU = A.
factorize <- function(A){
n <- nrow(A)
L <- diag(n)
D <- matrix(L,nrow=n, ncol=n)
U <- A
for (i in 1:(n - 1)) {
for (j in (i + 1):n) {
L[j,i] <- U[j,i] / U[i,i]
U[j,] <- U[j,] - L[j,i] * U[i,]
}
}
LDU <- list("L"=L, "D"=D, "U"=U)
return(LDU)
}
A <- matrix(c(1,2,3,4),nrow=2)
B <- matrix(c(1,2,3,4,5,6,7,8,9),nrow=3)
factorize(A)## $L
## [,1] [,2]
## [1,] 1 0
## [2,] 2 1
##
## $D
## [,1] [,2]
## [1,] 1 0
## [2,] 0 1
##
## $U
## [,1] [,2]
## [1,] 1 3
## [2,] 0 -2
factorize(A)$L %*% factorize(A)$D %*% factorize(A)$U == A## [,1] [,2]
## [1,] TRUE TRUE
## [2,] TRUE TRUE
factorize(B)## $L
## [,1] [,2] [,3]
## [1,] 1 0 0
## [2,] 2 1 0
## [3,] 3 2 1
##
## $D
## [,1] [,2] [,3]
## [1,] 1 0 0
## [2,] 0 1 0
## [3,] 0 0 1
##
## $U
## [,1] [,2] [,3]
## [1,] 1 4 7
## [2,] 0 -3 -6
## [3,] 0 0 0
factorize(B)$L %*% factorize(B)$D %*% factorize(B)$U == B## [,1] [,2] [,3]
## [1,] TRUE TRUE TRUE
## [2,] TRUE TRUE TRUE
## [3,] TRUE TRUE TRUE