1.Problem Set 1

  1. Show that \(A^T\)\(*A\) \(\neq\) \(A*\)\(A^T\) in general. (Proof and demonstration.)

Let’s assume that

\[A = \begin{pmatrix} a & b \\ c & d \\ e & f \\ \end{pmatrix}\]

The transpose of a matrix A is the matrix \(A^T\) whose rows are the columns of the matrix A.

\[A^T = \begin{pmatrix} a & c & e \\ b & d & f \\ \end{pmatrix}\]

For two matrices to be equal, they must be of the same size and have all the same entries.

If we multiply \(A^T\) by \(A\) we will get the matrix of the size 3x3. Whereas, if we multiply A by \(A^T\) we will get the matrix of the size 2x2.

So that, in order to be equal matrices \(A\) by \(A^T\) should have the same number of rows and columns. In other words the matrix A should have equal number of rows and numbers (be a squired matrix).

Let’s assume that the matrix A is squired.

\[A = \begin{pmatrix} a & b \\ c & d \\ \end{pmatrix}\]

Now we can build the transpose of a matrix A.

\[A^T = \begin{pmatrix} a & c \\ b & d \\ \end{pmatrix}\]

\[A*A^T= \left( \begin{array}{cc} a & b \\ c & d \end{array} \right) % \left( \begin{array}{cc} a & c \\ b & d \end{array} \right) = \left( \begin{array}{cc} a^2+b^2 & ac+bd \\ ac+bd & c^2+d^2 \end{array} \right)\]

\[A^T*A= \left( \begin{array}{cc} a & c \\ b & d \end{array} \right) % \left( \begin{array}{cc} a & b \\ c & d \end{array} \right) = \left( \begin{array}{cc} a^2+c^2 & ab+cd \\ ab+dc & b^2+d^2 \end{array} \right)\]

Since corresponding elements of \(A^T\)\(*A\) and \(A*\)\(A^T\) are not equal we can conclude that in general \(A^T\)\(*A\) \(\neq\) \(A*\)\(A^T\).

  1. For a special type of square matrix A, we get \(A^T\)\(*A\) \(\neq\) \(A*\)\(A^T\)

Under what conditions could this be true? (Hint: The Identity matrix I is an example of such a matrix).

As we already figured out the matrix A should be a squired matrix (the number of rows should be equal the number of columns).

The first case when \(A^T\)\(*A\) = \(A*\)\(A^T\) is when \(A^T\) equals to \(A\). When \(A^T\)=\(A\) we have \(A\)\(*A\) = \(A*\)\(A\). Hence, \(A^2\) = \(A^2\).

I figured out that first row of A should be equal to first column, second row of A should be equal to contuse column, etc. So that, corresponding row should be equal to corresponding column.

Let’s create such a matrix

\[A = \begin{pmatrix} a & b & c \\ b & c & d \\ c & d & e \\ \end{pmatrix}\]

Then the transpose matrix equal to

\[A^T = \begin{pmatrix} a & b & c \\ b & c & d \\ c & d & e \\ \end{pmatrix}\]

As you can see \(A^T\)=\(A\).

The other case when \(A^T\)\(*A\) = \(A*\)\(A^T\) is when the expression \(A^T\)\(*A\) equals to identity matrix. If \(A^T\)\(*A\) equals o Identity matrix then \(A^T\) equals \(A^-1\). When \(A^T\) equals \(A^-1\) \(A^-1\)\(*A\) = I = \(A\)\(*A^-1\)

1.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.

LU <- function(A,row_num,col_num) {

#create matrix L that consist of 0s    
L = matrix(c(0:0),nrow=row_num,  ncol=col_num, byrow = TRUE)

#assign 1s to the main diaginal
i=1

for (i in  1:3){
L[i,i]=1
} 

#assign matrix A to initial matrix U
U <- A
print("matrix A")
print(A)

#start from the first column
col=1

#iterate until col_num-1
for (col in  1:(col_num-1)){

#start to iterate from the second row  until final row 
row=col+1

  for (row in  (col+1):row_num){
    #U[row,col] = U[row,col]+x*U[col,col]    
    x=-U[row,col]/U[col,col]
    U[row,col] = 0
    
    #multiply the remaining elements of a current row by x 
    col2=col+1
    for (col2 in  (col+1):col_num){

    U[row,col2] = U[row,col2]+x*U[col,col2] 
    print("matrix U")
    print(U)   
    
  }
    
    #assign x to a corresponding cell in matrix L
    L[row,col] = -x
    
  } 
   
  
}

print("matrix L")
print(L)
#dot product of L and U should produce A
print("matrix LU=A")
print(L %*% U)
  
}

Let’s test matrix 3x3

row_num <- 3
col_num <- row_num
A = matrix(c(1:(row_num*col_num)),nrow=row_num,  ncol=col_num, byrow = TRUE)
LU(A,3,3)
## [1] "matrix A"
##      [,1] [,2] [,3]
## [1,]    1    2    3
## [2,]    4    5    6
## [3,]    7    8    9
## [1] "matrix U"
##      [,1] [,2] [,3]
## [1,]    1    2    3
## [2,]    0   -3    6
## [3,]    7    8    9
## [1] "matrix U"
##      [,1] [,2] [,3]
## [1,]    1    2    3
## [2,]    0   -3   -6
## [3,]    7    8    9
## [1] "matrix U"
##      [,1] [,2] [,3]
## [1,]    1    2    3
## [2,]    0   -3   -6
## [3,]    0   -6    9
## [1] "matrix U"
##      [,1] [,2] [,3]
## [1,]    1    2    3
## [2,]    0   -3   -6
## [3,]    0   -6  -12
## [1] "matrix U"
##      [,1] [,2] [,3]
## [1,]    1    2    3
## [2,]    0   -3   -6
## [3,]    0    0    0
## [1] "matrix L"
##      [,1] [,2] [,3]
## [1,]    1    0    0
## [2,]    4    1    0
## [3,]    7    2    1
## [1] "matrix LU=A"
##      [,1] [,2] [,3]
## [1,]    1    2    3
## [2,]    4    5    6
## [3,]    7    8    9