1, Show that ATA???AAT in general. (Proof and demonstration.)

library(matrixcalc)
library(Matrix)
## Warning: package 'Matrix' was built under R version 3.5.3
A <- matrix(c(1,2,3,4),nrow=2, ncol=2)
A;
##      [,1] [,2]
## [1,]    1    3
## [2,]    2    4
AT= t(A)
AT;
##      [,1] [,2]
## [1,]    1    2
## [2,]    3    4
AAT <- A %% AT
ATA <- AT %% A
identical(AAT, ATA)
## [1] FALSE
AAT
##      [,1] [,2]
## [1,]    0    1
## [2,]    2    0
ATA
##      [,1] [,2]
## [1,]    0    2
## [2,]    1    0

Conclusion: Therefore, ATA doesnโ€™t equal AAT.

2, For a special type of square matrix A, we get ATA=AAT. Under what conditions could this be true? (Hint: The Identity matrix I is an example of such a matrix).

A <- matrix(c(1,2,2,1),2,2)
A;
##      [,1] [,2]
## [1,]    1    2
## [2,]    2    1
AT= t(A)
AT
##      [,1] [,2]
## [1,]    1    2
## [2,]    2    1
AAT<-A %*% AT
ATA<-AT %*% A
identical(AAT, ATA)
## [1] TRUE
AAT
##      [,1] [,2]
## [1,]    5    4
## [2,]    4    5
ATA
##      [,1] [,2]
## [1,]    5    4
## [2,]    4    5

Conclusion: ATA=AAT.