(a) Show that AT A != A AT in general. (Proof and demonstration.)
#Let's create a basic 3 x 3 matrix, which we'll call mat1.
mat1 <- matrix(c(1,3,0,4,1,5,2,0,7), nrow = 3, byrow = TRUE)
mat1
## [,1] [,2] [,3]
## [1,] 1 3 0
## [2,] 4 1 5
## [3,] 2 0 7
# using R get the transpose for mat1 matrices.
mat1T <- t(mat1)
mat1T
## [,1] [,2] [,3]
## [1,] 1 4 2
## [2,] 3 1 0
## [3,] 0 5 7
#calculate both ATA and AAT.
ATA <- mat1T %*% mat1
ATA
## [,1] [,2] [,3]
## [1,] 21 7 34
## [2,] 7 10 5
## [3,] 34 5 74
AAT <- mat1 %*% mat1T
AAT
## [,1] [,2] [,3]
## [1,] 10 7 2
## [2,] 7 42 43
## [3,] 2 43 53
#It's clear that ATA???AAT for this "general" matrix.
# check programmaticaly AAT == ATA
AAT == ATA
## [,1] [,2] [,3]
## [1,] FALSE TRUE FALSE
## [2,] TRUE FALSE FALSE
## [3,] FALSE FALSE FALSE
(b) For a special type of square matrix A, we get AT A = AAT . Under what conditions could this be true? (Hint: The Identity matrix I is an example of such a matrix).
#Identity Matrix is a square matrix in which all the elements of the principal diagonal are ones and all other elements are zeros.
#Creating Identity matrix using R
A <- diag(3)
A
## [,1] [,2] [,3]
## [1,] 1 0 0
## [2,] 0 1 0
## [3,] 0 0 1
#transpose of A
AT <- t(A)
AT
## [,1] [,2] [,3]
## [1,] 1 0 0
## [2,] 0 1 0
## [3,] 0 0 1
# checking AT A = A AT
(A %*% t(A)) == (t(A) %*% A)
## [,1] [,2] [,3]
## [1,] TRUE TRUE TRUE
## [2,] TRUE TRUE TRUE
## [3,] TRUE TRUE TRUE