A <- matrix(c(1,1,1,2,0,-1,3,1,-2), nrow=3, byrow=TRUE)
AT <- t(A)
#Matrix A and its Transpose
A;
## [,1] [,2] [,3]
## [1,] 1 1 1
## [2,] 2 0 -1
## [3,] 3 1 -2
AT
## [,1] [,2] [,3]
## [1,] 1 2 3
## [2,] 1 0 1
## [3,] 1 -1 -2
#Multiplying A by its Transpose
A %*% AT
## [,1] [,2] [,3]
## [1,] 3 1 2
## [2,] 1 5 8
## [3,] 2 8 14
#Multiplying A Transpose by A
AT %*% A
## [,1] [,2] [,3]
## [1,] 14 4 -7
## [2,] 4 2 -1
## [3,] -7 -1 6
Above calculation proves that \(A^TA\) \(\ne\) \(AA^T\). We can check this further more by using logical comparision in R
A %*% AT == AT %*% A
## [,1] [,2] [,3]
## [1,] FALSE FALSE FALSE
## [2,] FALSE FALSE FALSE
## [3,] FALSE FALSE FALSE
#Square matrix A
A <- matrix(c(2,7,3,7,9,4,3,4,7), nrow=3, byrow=TRUE)
A
## [,1] [,2] [,3]
## [1,] 2 7 3
## [2,] 7 9 4
## [3,] 3 4 7
#Transpose of square matrix A
AT <- t(A)
AT
## [,1] [,2] [,3]
## [1,] 2 7 3
## [2,] 7 9 4
## [3,] 3 4 7
#Multiplying square matrix A by its Transpose
A %*% AT
## [,1] [,2] [,3]
## [1,] 62 89 55
## [2,] 89 146 85
## [3,] 55 85 74
#Multiplying square matrix A Transpose by square matrix A
AT %*% A
## [,1] [,2] [,3]
## [1,] 62 89 55
## [2,] 89 146 85
## [3,] 55 85 74
#logical comparision
A %*% AT == AT %*% A
## [,1] [,2] [,3]
## [1,] TRUE TRUE TRUE
## [2,] TRUE TRUE TRUE
## [3,] TRUE TRUE TRUE
Above calculations prove that if matrix A is symmetric/square, then \(A = A^T\) and \(A^TA\) \(=\) \(AA^T\).