(1) Show that \(\mathbf{A}^T\mathbf{A}\ne\mathbf{A}\mathbf{A}^T\) in general. (Proof and demonstration.)


Proof:


Let m be the number of rows in matrix \(\mathbf{A}\).
Let n be the number of columns in matrix \(\mathbf{A}\).


Let \(A_{m,n}\) = \(\left[ \begin{array}{ccc} a_{1,1} & a_{1,2} & a_{1,3} ..... & a_{1,m-1} & a_{1,n}\\ a_{2,1} & a_{2,2} & a_{2,3} ..... & a_{2,m-1} & a_{2,n}\\ ....\\ ....\\ ....\\ a_{m-1,1} & a_{m-2,2} & a_{m-1,3} ..... & a_{m-1,n-1} & a_{m-1,n}\\ a_{m,1} & a_{m,2} & a_{m,3} ..... & a_{m,n-1} & a_{m,n} \end{array} \right]\)


Let \(\mathbf{A}^T\) be the transpose of A.
By definition of transpose \(A_{m,n}\) is \(\mathbf{A}^T_{n,m}\).

Let \(\mathbf{A}^T_{n,m}\) = \(\mathbf{B}_{n,m}\) = \(\left[ \begin{array}{ccc} b_{1,1} & b_{1,2} & b_{1,3} ..... & b_{1,m-1} & b_{1,m}\\ b_{2,1} & b_{2,2} & b_{2,3} ..... & b_{2,m-1} & b_{2,m}\\ ....\\ ....\\ ....\\ b_{n-1,1} & b_{n-2,2} & b_{n-1,3} ..... & b_{m-1,n-1} & b_{n-1,m}\\ b_{n,1} & b_{n,2} & b_{n,3} ..... & b_{n,m-1} & b_{n,m} \end{array} \right]\)

Let \(\mathbf{A}^T_{n,m}\mathbf{A}_{m,n}\) = \(\mathbf{C}_{m,m}\).
Let \(\mathbf{A}_{m,n}\mathbf{A}^T_{n,m}\) = \(\mathbf{D}_{n,n}\).
Therefore \(\mathbf{C}_{m,m}\ne\mathbf{D}_{n,n}\) since m \(\ne\) n in general (except for square matrices).

For square matrices -

Let \(\mathbb{a}_{i,j}\) be the elements of square matrix \(\mathbf{A}\) where i is the row and j is the column and where i and j = 1 to m.

Let \(\mathbf{A}^T_{m,m}\) = \(\mathbf{B}_{m,m}\) be the elements of square matrix \(\mathbf{B}\) where j is the row and i is the column and where i and j = 1 to m.

Since -
\(\mathbf{B}_{m,m}\mathbf{A}_{m,m}\) = \(\mathbf{C}_{m,m}\)[\(\mathbb{a}_{i,j}\cdot\mathbb{b}_{j,i}\)] for each element of the product matrix and
\(\mathbf{A}_{m,m}\mathbf{B}_{m,m}\) = \(\mathbf{D}_{m,m}\)[\(\mathbb{b}_{j,i}\cdot\mathbb{a}_{i,j}\)] for each element of the product matrix.

Therefore -
\(\mathbf{C}_{m,m}\)[\(\mathbb{a}_{i,j}\cdot\mathbb{b}_{j,i}\)] \(\ne\) \(\mathbf{D}_{m,m}\)[\(\mathbb{b}_{i,j}\cdot\mathbb{a}_{j,i}\)] for any square matrix,
since \(\mathbb{a}_{i,j}\ne\mathbb{a}_{j,i}\) and \(\mathbb{b}_{j,i}\ne\mathbb{a}_{i,j}\) in general.



Demonstration:



Let \(\mathbf{A}_{3,4}\) = \(\left[ \begin{array}{ccc} 3 & 7 & 4 & 11\\ 13 & 5 & 4 & 1\\ 1 & 0 & 0 & 5 \end{array} \right]\)

A = matrix(c(3,7,4,11,13, 5, 4, 1, 1, 0, 0, 5), nrow=3, byrow=TRUE)
A
##      [,1] [,2] [,3] [,4]
## [1,]    3    7    4   11
## [2,]   13    5    4    1
## [3,]    1    0    0    5

\(\mathbf{A}^T_{4,3}\)

t(A)
##      [,1] [,2] [,3]
## [1,]    3   13    1
## [2,]    7    5    0
## [3,]    4    4    0
## [4,]   11    1    5

\(\mathbf{A}^T\mathbf{A}\)=\(\mathbf{A}\mathbf{A}^T\)?

t(A)%*%A 
##      [,1] [,2] [,3] [,4]
## [1,]  179   86   64   51
## [2,]   86   74   48   82
## [3,]   64   48   32   48
## [4,]   51   82   48  147
A%*%t(A)
##      [,1] [,2] [,3]
## [1,]  195  101   58
## [2,]  101  211   18
## [3,]   58   18   26

Answer: no



For a square matrix, let \(\mathbf{A}_{4,4}\) = \(\left[ \begin{array}{ccc} 1 & 2 & 3 & 4\\ 4 & 3 & 2 & 1\\ 5 & 6 & 7 & 8\\ 8 & 7 & 6 & 5 \end{array} \right]\)

A = matrix(c(1,2,3,4,4,3,2,1,5,6,7,8,8,7,6,5), nrow=4, byrow=TRUE)
A
##      [,1] [,2] [,3] [,4]
## [1,]    1    2    3    4
## [2,]    4    3    2    1
## [3,]    5    6    7    8
## [4,]    8    7    6    5

\(\mathbf{A}^T\mathbf{A}\)=\(\mathbf{A}\mathbf{A}^T\)?

t(A)%*%A 
##      [,1] [,2] [,3] [,4]
## [1,]  106  100   94   88
## [2,]  100   98   96   94
## [3,]   94   96   98  100
## [4,]   88   94  100  106
A%*%t(A)
##      [,1] [,2] [,3] [,4]
## [1,]   30   20   70   60
## [2,]   20   30   60   70
## [3,]   70   60  174  164
## [4,]   60   70  164  174
t(A)%*%A == A%*%t(A)
##       [,1]  [,2]  [,3]  [,4]
## [1,] FALSE FALSE FALSE FALSE
## [2,] FALSE FALSE FALSE FALSE
## [3,] FALSE FALSE FALSE FALSE
## [4,] FALSE FALSE FALSE FALSE

Answer: no




(2) For a special type of square matrix \(\mathbf{A}\), we get \(\mathbf{A}^T\mathbf{A}\)=\(\mathbf{A}\mathbf{A}^T\). Under what conditions can this be true?



Answer -

\(\mathbf{A}^T\mathbf{A}\)=\(\mathbf{A}\mathbf{A}^T\) is true for special cases where the row elements of the square matrix are identical to the corresponding column elements. That is,
\(\left[ \begin{array}{ccc} a_{i,j} & a_{i,j+1} & a_{i,j+2} ..... & a_{i,m-1} & a_{i,m} \end{array} \right]\) = \(\left[ \begin{array}{ccc} b_{i,j}\\ b_{i+1,j}\\ b_{i+2,j}\\ ....\\ ....\\ b_{m-1,j}\\ b_{m,j} \end{array} \right]\) where i,j values are from 1 to m of a \(\mathbf{A}_{m,m}\) square matrix


Demonstrations:


For a square matrix, let \(\mathbf{A}_{5,5}\) = \(\left[ \begin{array}{ccc} 1 & 2 & 3 & 4 & 5\\ 2 & 1 & 6 & 7 & 8\\ 3 & 6 & 1 & 9 & 10\\ 4 & 7 & 9 & 1 & 11\\ 5 & 8 & 10 & 11 & 1 \end{array} \right]\)

A = matrix(c(1,2,3,4,5,2,1,6,7,8,3,6,1,9,10,4,7,9,1,11,5,8,10,11,1), nrow=5, byrow=TRUE)
A
##      [,1] [,2] [,3] [,4] [,5]
## [1,]    1    2    3    4    5
## [2,]    2    1    6    7    8
## [3,]    3    6    1    9   10
## [4,]    4    7    9    1   11
## [5,]    5    8   10   11    1

\(\mathbf{A}^T\mathbf{A}\)=\(\mathbf{A}\mathbf{A}^T\)?

t(A)%*%A 
##      [,1] [,2] [,3] [,4] [,5]
## [1,]   55   90  104  104  100
## [2,]   90  154  161  164  163
## [3,]  104  161  227  182  182
## [4,]  104  164  182  268  188
## [5,]  100  163  182  188  311
A%*%t(A)
##      [,1] [,2] [,3] [,4] [,5]
## [1,]   55   90  104  104  100
## [2,]   90  154  161  164  163
## [3,]  104  161  227  182  182
## [4,]  104  164  182  268  188
## [5,]  100  163  182  188  311
t(A)%*%A == A%*%t(A)
##      [,1] [,2] [,3] [,4] [,5]
## [1,] TRUE TRUE TRUE TRUE TRUE
## [2,] TRUE TRUE TRUE TRUE TRUE
## [3,] TRUE TRUE TRUE TRUE TRUE
## [4,] TRUE TRUE TRUE TRUE TRUE
## [5,] TRUE TRUE TRUE TRUE TRUE

Answer: yes

For a square matrix, let \(\mathbf{A}_{4,4}\) = \(\left[ \begin{array}{ccc} 18 & 2 & 3 & 4\\ 2 & 15 & 6 & 7\\ 3 & 6 & 13 & 9\\ 4 & 7 & 9 & 14 \end{array} \right]\)

A = matrix(c(1,2,3,4,2,15,6,7,3,6,13,9,4,7,9,14), nrow=4, byrow=TRUE)
A
##      [,1] [,2] [,3] [,4]
## [1,]    1    2    3    4
## [2,]    2   15    6    7
## [3,]    3    6   13    9
## [4,]    4    7    9   14

\(\mathbf{A}^T\mathbf{A}\)=\(\mathbf{A}\mathbf{A}^T\)?

t(A)%*%A 
##      [,1] [,2] [,3] [,4]
## [1,]   30   78   90  101
## [2,]   78  314  237  265
## [3,]   90  237  295  297
## [4,]  101  265  297  342
A%*%t(A)
##      [,1] [,2] [,3] [,4]
## [1,]   30   78   90  101
## [2,]   78  314  237  265
## [3,]   90  237  295  297
## [4,]  101  265  297  342
t(A)%*%A == A%*%t(A)
##      [,1] [,2] [,3] [,4]
## [1,] TRUE TRUE TRUE TRUE
## [2,] TRUE TRUE TRUE TRUE
## [3,] TRUE TRUE TRUE TRUE
## [4,] TRUE TRUE TRUE TRUE

Answer: yes

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 flights 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 flight using radars. Write an R function to factorize a square matrix A into LU or LDU, whichever you prefer.

Matrix Factorization Using LU Decomposition

LUD <- function (M)
{
r = dim(M)[1]
U = M
L = matrix(0,r,r)
for (x in 1:r)
{
 L[x,x] = 1 
}
M
U
L
for (p in 1:(r-1))
{
 for (i in p:(r-1))                            #row
 {
  mult = ((U[i+1,p])/(U[p,p])) 
  L[i+1,p] = mult 
  print (mult)
  for (j in p:r)                               #column
  {  
    U[i+1,j] = U[i+1,j] - U[p,j]*mult 
   }
 }
}
U
L
df = data.frame(U,L)
return(df)
}

#M = matrix(c(1, 2, -1, 1, -1, -2, 3, 5, 4), nrow=3)
#M
#s <- LUD(M)
#print(s)
M = matrix(c(2, 1, -6, 4, -4, -9, -4, 3, 5), ncol=3)
#M
s <- LUD(M)
## [1] 0.5
## [1] -3
## [1] -0.5
print(s)
##   X1 X2   X3 X1.1 X2.1 X3.1
## 1  2  4 -4.0  1.0  0.0    0
## 2  0 -6  5.0  0.5  1.0    0
## 3  0  0 -4.5 -3.0 -0.5    1