Problem Set 1

# To test it out with values
A <- matrix(c(1,2,3,4), nrow = 2)
AT <- matrix(c(1,2,3,4), nrow = 2, byrow = T)

#AT * A
Det_A_result1 <- AT %*% A
Det_A_result2 <- A %*% AT

Based on the result below, this shows that the equation ATxA is not equal to the equation AxAT since the result is different. For both equations to be equal, it needs to be an identity matrix where the diagonal from upper left to bottom right needs to be 1.

Det_A_result1
##      [,1] [,2]
## [1,]    5   11
## [2,]   11   25
Det_A_result2
##      [,1] [,2]
## [1,]   10   14
## [2,]   14   20

Problem Set 2

# matrix LU function
lu_matrix_function <- function(x){
 n_row <- nrow(x)
 value <- x
 diag <- diag(n_row)
 for (a in c(1:n_row)){
   for (b in c(2:n_row)){
     if(b > a){
       value_row = value[a,]
       value_multiply = value[b,a]/value_row[a]
       value[b,] = value[b,] - (value_row * value_multiply)
       diag[b,a] = value_multiply
     }
   }
 }
 return(list(upper = value, lower = diag))
}

# Test result for A
lu_matrix_function(A)
## $upper
##      [,1] [,2]
## [1,]    1    3
## [2,]    0   -2
## 
## $lower
##      [,1] [,2]
## [1,]    1    0
## [2,]    2    1