##Question 1
Consider a matrix A:
A <- matrix(c(10, 00, 00), ncol=1, byrow=TRUE)
Then \(A^T=\)
AT <- t(A)
dim(AT)
## [1] 1 3
So \(AA^T=\)
AAT <- A%*%AT
dim(AAT)
## [1] 3 3
And \(A^TA\)
ATA <- AT%*%A
dim(ATA)
## [1] 1 1
dim(AAT)
## [1] 3 3
Since the dimensions of \(AA^T\neq\ A^TA,\) the matrices are not equal (in general)
This is true only if \(A=A^T\). This is qualitatively defined as a symmetric matrix.
Identity matrix is quintessential example but there are other examples of symmetric matrix.
A <- diag(3)
AT <- t(A)
AAT <- A%*%AT
ATA <- AT%*%A
ATA==AAT
## [,1] [,2] [,3]
## [1,] TRUE TRUE TRUE
## [2,] TRUE TRUE TRUE
## [3,] TRUE TRUE TRUE
factor_matrix <- function(A) {
size <- nrow(A)
max <- size - 1
# Build our base L matrix
L <- matrix(0, nrow=size, ncol=size)
for (i in 1:size) {
L[i,i] = 1L
}
# Copy A into U - we will be decompsing U as we go and keep our orig A
U <- matrix(0, nrow=size, ncol=size)
for (r in 1:size) {
for (c in 1:size) {
U[r,c] <- A[r,c]
}
}
for (c in 1:max) {
base_row <- c
next_row <- c+1
for (r in next_row:size) {
# print(c(c, r))
L[r, c] = U[r, c] / U[base_row, c]
U[r,] = U[r,] - U[base_row,] * L[r, c]
}
}
U <- round(U, 5)
L <- round
return(list("A"=A, "U"=U, "L"=L))
}
matrix_size <- 6
A <- matrix(sample(-100:100, matrix_size^2), byrow=T, nrow=matrix_size, ncol=matrix_size)
result <- factor_matrix(A)
print(result)
## $A
## [,1] [,2] [,3] [,4] [,5] [,6]
## [1,] 17 -2 64 1 -34 40
## [2,] -21 42 62 36 -84 -79
## [3,] 21 -78 55 -55 45 13
## [4,] 91 -22 39 -40 -30 15
## [5,] 48 97 -95 -87 9 -29
## [6,] 49 65 -47 -32 93 78
##
## $U
## [,1] [,2] [,3] [,4] [,5] [,6]
## [1,] 17 -2.00000 64.0000 1.00000 -34.0000 40.00000
## [2,] 0 39.52941 141.0588 37.23529 -126.0000 -29.58824
## [3,] 0 0.00000 245.4643 14.91071 -153.7500 -92.94643
## [4,] 0 0.00000 0.0000 -18.72101 -48.9127 -307.26604
## [5,] 0 0.00000 0.0000 0.00000 415.4794 2112.94963
## [6,] 0 0.00000 0.0000 0.00000 0.0000 -518.84385
##
## $L
## function (x, digits = 0) .Primitive("round")