Let A be a m x n matrix. By definition its transpose \(\mathbf{A}^\intercal\) will be n x m matrix.
Given the definition of matrix multiplication, multiplying A to \(\mathbf{A}^\intercal\) will return a m x m square matrix.
Similarly multiplying \(\mathbf{A}^\intercal\) to A will return a n x n matix.
Therefore if m \(\neq\) n then result of \(A\) \(\mathbf{A}^\intercal\) dimension would be different of \(\mathbf{A}^\intercal\) \(A\)
hence \(A\) \(\mathbf{A}^\intercal\) \(\neq\) \(\mathbf{A}^\intercal\) \(A\)
\(A = \left( \begin{matrix} 1&2&3\\ 4&5&6 \end{matrix} \right)\) \(\mathbf{A}^\intercal\) = \(\left( \begin{matrix} 1&4\\ 2&5\\ 3&6 \end{matrix} \right)\)
\(A\) \(\mathbf{A}^\intercal\) = \(\left( \begin{matrix} 1&2&3\\ 4&5&6 \end{matrix} \right)\) x \(\left( \begin{matrix} 1&4\\ 2&5\\ 3&6 \end{matrix} \right)\) = \(\left( \begin{matrix} 14&32\\ 32&77 \end{matrix} \right)\)
\(\mathbf{A}^\intercal\) \(A\) = \(\left( \begin{matrix} 1&4\\ 2&5\\ 3&6 \end{matrix} \right)\) x \(\left( \begin{matrix} 1&2&3\\ 4&5&6 \end{matrix} \right)\) = \(\left( \begin{matrix} 17&22&27\\ 22&29&36\\ 27&36&45 \end{matrix} \right)\)
hence \(A\) \(\mathbf{A}^\intercal\) \(\neq\) \(\mathbf{A}^\intercal\) \(A\)
For symmetric matrix \(A\) = \(\mathbf{A}^\intercal\) then \(A\) \(\mathbf{A}^\intercal\) = \(\mathbf{A}^\intercal\) \(A\)
matrix A is symmetric if \(a_{ij}\) = \(a_{ji}\) for all i,j
A = \(\left( \begin{matrix} 1&2&3\\ 2&3&4 \\ 3&4&7 \end{matrix} \right)\) \(\mathbf{A}^\intercal\) = \(\left( \begin{matrix} 1&2&3\\ 2&3&4 \\ 3&4&7 \end{matrix} \right)\)
\(A\) \(\mathbf{A}^\intercal\) = \(\mathbf{A}^\intercal\) \(A\) = \(\left( \begin{matrix} 1&2&3\\ 2&3&4 \\ 3&4&7 \end{matrix} \right)\) x \(\left( \begin{matrix} 1&2&3\\ 2&3&4 \\ 3&4&7 \end{matrix} \right)\) = \(\left( \begin{matrix} 14&20&32\\ 20&29&46 \\ 3&46&74 \end{matrix} \right)\)
library(matrixcalc)
LU_factorization <- function(A) {
# To check first if given matrix is a square matrix
if(is.square.matrix(A) == FALSE) {
return("Only square matrix is allowed here.")
}
U <- A
n <- dim(A)[1]
# identity matrix
L <- diag(n)
if(n==1){
return(list(L,U))
}
for(i in 2:n){
for(j in 1:(i-1)) {
m <- -U[i,j] / U[j,j]
U[i,] <- m * U[j,] + U[i,]
L[i,j] <- -m
}
}
return(list(L,U))
}
A <- matrix(c(1,2,3,
4,5,6,
7,8,9), byrow = T, ncol = 3)
A
## [,1] [,2] [,3]
## [1,] 1 2 3
## [2,] 4 5 6
## [3,] 7 8 9
lu <- LU_factorization(A)
lu
## [[1]]
## [,1] [,2] [,3]
## [1,] 1 0 0
## [2,] 4 1 0
## [3,] 7 2 1
##
## [[2]]
## [,1] [,2] [,3]
## [1,] 1 2 3
## [2,] 0 -3 -6
## [3,] 0 0 0