Show that AT A # AAT in general. (Proof and demonstration.)
Proof: Assum A is a 3*2 matrix, then AT is 2*3 matrix.
A * AT should be a 3*3 matrix, whereas AT*A is a 2*2 matrix
Thus, A * AT not equal to AT*A in general
Demonstration
a = matrix(c(1, 4, 7, 2, 5, 8, 3), nrow=3, ncol=2)
## Warning in matrix(c(1, 4, 7, 2, 5, 8, 3), nrow = 3, ncol = 2): data length
## [7] is not a sub-multiple or multiple of the number of rows [3]
a
## [,1] [,2]
## [1,] 1 2
## [2,] 4 5
## [3,] 7 8
t(a)
## [,1] [,2] [,3]
## [1,] 1 4 7
## [2,] 2 5 8
a%*%t(a)
## [,1] [,2] [,3]
## [1,] 5 14 23
## [2,] 14 41 68
## [3,] 23 68 113
t(a)%*%a
## [,1] [,2]
## [1,] 66 78
## [2,] 78 93
For a special type of square matrix A, we get AT A = AAT Under what conditionscould this be true?
When a matrix is Symmetric matrix or antisymmetric matrix or orthogonal matrix, AT * A = A * AT
sfunc <- function (n, i, x) {
s <- diag (n)
s [i, i] <- x
return (s)
}
tfunc <- function (n, i, j, x) {
t <- diag (n)
t [i, j] <- x
return (t)
}
gaussMatrixForward <- function (a, verbose = TRUE) {
n <- nrow (a)
for (i in 1 : n) {
a <- sfunc (n, i, 1 / a[i, i]) %*% a
if (i == n) {
break ()
}
for (j in (i + 1) : n) {
a <- tfunc (n, j, i, - a[j, i]) %*% a
}
}
return (a)
}
LU_decomp <- function (a) {
n <- nrow (a)
g <- gaussMatrixForward (cbind (a, diag (n)))
h <- gaussMatrixForward (cbind (g[, n + 1 : n], diag (n)))
return (list (L = h[, n + 1 : n], U = g [, 1 : n]))
}
set.seed (12345)
print (a <- matrix (sample (16), 4, 4))
## [,1] [,2] [,3] [,4]
## [1,] 12 6 13 3
## [2,] 14 2 7 9
## [3,] 11 4 1 10
## [4,] 16 5 8 15
print (lu <- LU_decomp (a))
## $L
## [,1] [,2] [,3] [,4]
## [1,] 12 0.0 0.000000 0.000000
## [2,] 14 -5.0 0.000000 0.000000
## [3,] 11 -1.5 -8.466667 0.000000
## [4,] 16 -3.0 -4.433333 4.767717
##
## $U
## [,1] [,2] [,3] [,4]
## [1,] 1 0.5 1.083333 0.2500000
## [2,] 0 1.0 1.633333 -1.1000000
## [3,] 0 0.0 1.000000 -0.6614173
## [4,] 0 0.0 0.000000 1.0000000
library(matrixcalc)
A <- matrix( c ( 1, 2, 2, 1 ), nrow=2, byrow=TRUE)
luA <- lu.decomposition( A )
luA
## $L
## [,1] [,2]
## [1,] 1 0
## [2,] 2 1
##
## $U
## [,1] [,2]
## [1,] 1 2
## [2,] 0 -3