Both of these querstions can be answered at the same time. In multiplying matrices, position matters. If we make a modification to the matrix formula, it becomes clearer. If we replace \({ A }^{ T }\) with “B” we get \(\left[ A \right] \left[ B \right] \neq \left[ B \right] \left[ A \right]\). This statement is completely true.
However, stepping out side of the above example, multiplying a matrix (\(m\times n\)) by its transpose (\(n\times m\)) will always result in a square (\(m\times m\)) matrix where as multiplying a Transpose (\(n\times m\)) by its matrix (\(m\times n\)) will result in a (\(n\times n\))
\[(n\times n)\neq (m\times m)\] The dimensions to not match in all cases
\[A=\begin{bmatrix} 2 & 3 & 4 \\ 5 & 6 & 7 \end{bmatrix}\quad then\quad { A }^{ T }=\quad \begin{vmatrix} 2 & 5 \\ 3 & 6 \\ 4 & 7 \end{vmatrix}\] \[\begin{bmatrix} 2 & 3 & 4 \\ 5 & 6 & 7 \end{bmatrix}*\begin{vmatrix} 2 & 5 \\ 3 & 6 \\ 4 & 7 \end{vmatrix}=\quad \begin{bmatrix} 29 & 56 \\ 56 & 110 \end{bmatrix}\]
\[{ A }^{ T }=\quad \begin{vmatrix} 2 & 5 \\ 3 & 6 \\ 4 & 7 \end{vmatrix}\quad then\quad A=\begin{bmatrix} 2 & 3 & 4 \\ 5 & 6 & 7 \end{bmatrix}\]
\[\begin{vmatrix} 2 & 5 \\ 3 & 6 \\ 4 & 7 \end{vmatrix}*\begin{bmatrix} 2 & 3 & 4 \\ 5 & 6 & 7 \end{bmatrix}=\begin{bmatrix} 29 & 36 & 43 \\ 36 & 45 & 54 \\ 43 & 54 & 65 \end{bmatrix}\]
If A is completely equal to \({ A }^{ T }\), such as a symmetric matrix, then \({ A }^{ T }A=A{ A }^{ T }\) as the multiplcation of the matrices will not differ in the position of the multiplication.
\[\begin{bmatrix} 2 & 3 & 4 \\ 3 & 4 & 5 \\ 4 & 5 & 6 \end{bmatrix}=\begin{vmatrix} 2 & 3 & 4 \\ 3 & 4 & 5 \\ 4 & 5 & 6 \end{vmatrix}\]
Problem Set 2
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 ltering. At the heart of Kalman Filtering is a Matrix Factorization operation. Kalman Filters are solving linear systems of equations when they track your light using radars.
Write an R function to factorize a square matrix A into LU or LDU, whichever you prefer.
LU_factor <- function(A) {
# Ensure Matrix is Square
if(dim(A)[1]!=dim(A)[2]){
return('STOP! Matrix is not square')
}
r <- c <- dim(A)[1]
L <- D <- matrix(diag(r), ncol=c, nrow = r)
U <- A
for(w in 1: (c-1)){
for (q in (w+1):r) {
L[q,w]= (U[q,w]/U[w,w])
U[q,]= U[q,]-(U[w,]*L[q,w])
}
}
diag(D) = diag(U)
for (g in 1:r){
U[g,]=U[g,]/U[g,g]
}
LU <- list("Lower Matrix"=L, "Upper Matrix"=U, "Diagonal Matrix"=D)
return(LU)
}
rank = 4
set.seed(5)
x <- rnorm(rank^2)
Q2 <- matrix(x, nrow=rank); Q2
## [,1] [,2] [,3] [,4]
## [1,] -0.84085548 1.7114409 -0.2857736 -1.0803926
## [2,] 1.38435934 -0.6029080 0.1381082 -0.1575344
## [3,] -1.25549186 -0.4721664 1.2276303 -1.0717600
## [4,] 0.07014277 -0.6353713 -0.8017795 -0.1389861
LU_factor(Q2)
## $`Lower Matrix`
## [,1] [,2] [,3] [,4]
## [1,] 1.00000000 0.0000000 0.0000000 0
## [2,] -1.64637013 1.0000000 0.0000000 0
## [3,] 1.49311254 -1.3669852 1.0000000 0
## [4,] -0.08341834 -0.2224198 -0.7496452 1
##
## $`Upper Matrix`
## [,1] [,2] [,3] [,4]
## [1,] 1 -2.035357 0.3398606 1.2848731
## [2,] 0 1.000000 -0.1500756 -0.8742541
## [3,] 0 0.000000 1.0000000 -1.7545976
## [4,] 0 0.000000 0.0000000 1.0000000
##
## $`Diagonal Matrix`
## [,1] [,2] [,3] [,4]
## [1,] -0.8408555 0.000000 0.000000 0.000000
## [2,] 0.0000000 2.214757 0.000000 0.000000
## [3,] 0.0000000 0.000000 1.199963 0.000000
## [4,] 0.0000000 0.000000 0.000000 -2.238115
References:
https://www.youtube.com/watch?v=m3EojSAgIao https://www.youtube.com/watch?v=gA7m5lttIcU https://rpubs.com/betsyrosalen/DATA605_Assignment2 (I had difficulty with the Diagonal) https://www.khanacademy.org/math/linear-algebra/matrix-transformations/determinant-depth/v/linear-algebra-upper-triangular-determinant