Problem Set 1:

1) Prove \(AA^T\neq A^TA\):

Let \(A\) be a \(n \times m\) matrix. If \(n\neq m\), \(AA^T\) results in a \(n \times n\) matrix and \(A^TA\) results in a \(m \times m\) matrix. Since the two matrices have different sizes, they cannot be equal.

In R:

A<-matrix(c(1,2,3,1,2,3),nrow=2)
B<-t(A)
A%*%B
##      [,1] [,2]
## [1,]   14   11
## [2,]   11   14
B%*%A
##      [,1] [,2] [,3]
## [1,]    5    5    8
## [2,]    5   10    9
## [3,]    8    9   13

2) Under what conditions could \(A^TA=AA^T\)?

If a matrix A is involuntary, it follows that \(A^TA=AA^T=I\). Singular matrices cannot be commutable with their transposes. Likewise diagonal matrices commute with each other.

Looking up the answer, if two matrices are diagonalizable by the same matrix pair, they commute. That is to say, if \(PAP^{-1}\) and \(PBP^{-1}\) are both diagonal, \(AB=BA\). So if \(A\) and \(A^T\) are diagonalizable by a matrix and its inverse, they commute.

A quick proof of this:

Let \(D_1\) and \(D_2\) be diagonal matrices and \(P\) and \(A\) matrices such that \(PAP^{-1}=D_1\) and \(PA^TP^{-1}=D_2\). \(D_1D_2=PAP^{-1}PA^TP^{-1}\). Because \(PP^{-1}=I\), \(D_1D_2=PAA^TP^{-1}\). So \(P^{-1}D_1D_2P=AA^T\). Likewise, \(P^{-1}D_2D_1P=A^TA\). Since we know that \(D_1D_2\)=\(D_2D_1\), \(AA^T=P^{-1}D_1D_2P=P^{-1}D_2D_1P=A^TA\).

Problem Set 2

LUme <- function(A){ #A is the original matrix #apparently decompose is already kicking around, thus the function name.
  size = nrow(A)
  lower<-diag(size)
  usethis <- size-1
  ##this should be doable via lapply, but given that what needs to be done to the lower matrix is so difference than the upper
  ##I ended up just doing two nested loops so that this can handle arbitrary sized non-singular matrices
  for (i in 1:usethis){
    for (j in i:size){
      if(j<size){
        container<-rUeL(A,lower,i,j+1)
        A<-container[[1]]
        lower<-container[[2]]
      }
    }
  }
  answerlist<-list(lower,A,lower%*%A)
  names(answerlist)<-c("Lower Matrix","Upper Matrix","Multiplied")
  return(answerlist)
  }

rUeL <- function(m1,m2,r1,r2){ #m1 is the upper matrix, m2 is the lower, r1 is the row above r2
  coef<-(m1[r2,r1]/m1[r1,r1]) #coefficient for subtraction of r1 and r2 to zero out the appropriate element of r2
  m1[r2,]<-m1[r2,]-(m1[r1,]*m1[r2,r1]/m1[r1,r1])
  m2[r2,r1]<-coef
  return(list(m1,m2))
}

##in action
m<-matrix(c(2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 91),nrow=5)

m
##      [,1] [,2] [,3] [,4] [,5]
## [1,]    2   13   31   53   73
## [2,]    3   17   37   59   79
## [3,]    5   19   41   61   83
## [4,]    7   23   43   67   89
## [5,]   11   29   47   71   91
LUme(m)
## $`Lower Matrix`
##      [,1] [,2]     [,3]     [,4] [,5]
## [1,]  1.0  0.0 0.000000 0.000000    0
## [2,]  1.5  1.0 0.000000 0.000000    0
## [3,]  2.5  5.4 1.000000 0.000000    0
## [4,]  3.5  9.0 1.351351 1.000000    0
## [5,]  5.5 17.0 2.567568 2.099585    1
## 
## $`Upper Matrix`
##      [,1] [,2] [,3]      [,4]       [,5]
## [1,]    2 13.0 31.0  53.00000  73.000000
## [2,]    0 -2.5 -9.5 -20.50000 -30.500000
## [3,]    0  0.0 14.8  39.20000  65.200000
## [4,]    0  0.0  0.0  13.02703  19.891892
## [5,]    0  0.0  0.0   0.00000  -1.170124
## 
## $Multiplied
##      [,1] [,2] [,3] [,4] [,5]
## [1,]    2   13   31   53   73
## [2,]    3   17   37   59   79
## [3,]    5   19   41   61   83
## [4,]    7   23   43   67   89
## [5,]   11   29   47   71   91