Given \(A\) as an \(m \times n\) matrix, \(A^T\) is an \(n \times m\) matrix.
The product \(A^TA\) results in an \(n \times n\) matrix, while \(AA^T\) results in an \(m \times m\) matrix.
Let’s take a matrix \(A\):
\[ A = \begin{pmatrix} 1 & 2 \\ 3 & 4 \\ \end{pmatrix} \]
The transpose, \(A^T\), is:
\[ A^T = \begin{pmatrix} 1 & 3 \\ 2 & 4 \\ \end{pmatrix} \]
Calculating \(A^TA\):
\[ A^TA = \begin{pmatrix} 1 & 3 \\ 2 & 4 \\ \end{pmatrix} \begin{pmatrix} 1 & 2 \\ 3 & 4 \\ \end{pmatrix} = \begin{pmatrix} 10 & 14 \\ 14 & 20 \\ \end{pmatrix} \]
Calculating \(AA^T\):
\[ AA^T = \begin{pmatrix} 1 & 2 \\ 3 & 4 \\ \end{pmatrix} \begin{pmatrix} 1 & 3 \\ 2 & 4 \\ \end{pmatrix} = \begin{pmatrix} 5 & 11 \\ 11 & 25 \\ \end{pmatrix} \]
Thus, \(A^TA \neq AA^T\), demonstrating that in general, \(A^TA \neq AA^T\).
For the equality \(A^TA = AA^T\) to hold, the matrix \(A\) must satisfy certain conditions. This is true for:
Here is R function for LU decomposition of a square matrix
luDecomposition <- function(A) {
if (!is.matrix(A)) {
stop("Input must be a matrix.")
}
n <- nrow(A)
if (ncol(A) != n) {
stop("Matrix must be square.")
}
L <- diag(1, n) # Initializing L as an identity matrix of size n
U <- A # Copying A into U for transformation
for (j in 1:(n-1)) {
for (i in (j+1):n) {
if (U[j, j] == 0) {
stop("Zero pivot encountered.")
}
L[i, j] <- U[i, j] / U[j, j]
U[i, ] <- U[i, ] - L[i, j] * U[j, ]
}
}
return(list(L = L, U = U))
}
An example of Application using the LU function above:
A <- matrix(c(1, 2, 1, 3,
3, 8, 1, 5,
0, 4, 1, 9,
4, 11, 3, 0), byrow = TRUE, nrow = 4)
result <- luDecomposition(A)
print("L Matrix:")
## [1] "L Matrix:"
print(result$L)
## [,1] [,2] [,3] [,4]
## [1,] 1 0.0 0.0 0
## [2,] 3 1.0 0.0 0
## [3,] 0 2.0 1.0 0
## [4,] 4 1.5 0.4 1
print("U Matrix:")
## [1] "U Matrix:"
print(result$U)
## [,1] [,2] [,3] [,4]
## [1,] 1 2 1 3.0
## [2,] 0 2 -2 -4.0
## [3,] 0 0 5 17.0
## [4,] 0 0 0 -12.8