We can create any random matrix and its transpose
rm <- matrix(rnorm(9),nrow=3,ncol=3)
rm
## [,1] [,2] [,3]
## [1,] 1.192519 -1.66701254 0.3448809
## [2,] 2.512014 -0.09525945 1.9642515
## [3,] -1.191574 -1.50170926 -0.8364461
rmt <- t(rm)
rmt
## [,1] [,2] [,3]
## [1,] 1.1925191 2.51201423 -1.1915737
## [2,] -1.6670125 -0.09525945 -1.5017093
## [3,] 0.3448809 1.96425154 -0.8364461
Products:
rm_rmt <- rm %*% rmt
rm_rmt
## [,1] [,2] [,3]
## [1,] 4.3199754 3.831856 0.7939195
## [2,] 3.8318565 10.177574 -4.4931887
## [3,] 0.7939195 -4.493189 4.3746207
rmt_rm <- rmt %*% rm
rmt_rm
## [,1] [,2] [,3]
## [1,] 9.1521652 -0.4378401 6.3421921
## [2,] -0.4378401 5.0431359 0.4940645
## [3,] 6.3421921 0.4940645 4.6768690
Equivalence:
rm_rmt == rmt_rm
## [,1] [,2] [,3]
## [1,] FALSE FALSE FALSE
## [2,] FALSE FALSE FALSE
## [3,] FALSE FALSE FALSE
Under what conditions could this be true? (Hint: The Identity matrix I is an example of such a matrix). Please typeset your response using LaTeX mode in RStudio. If you do it in paper, please either scan or take a picture of the work and submit it. Please ensure that your image is legible and that your submissions are named using your first initial, last name, assignment and problem set within the assignment. E.g. LFulton_Assignment2_PS1.png
Since we know that the identity matrix is an example, we can use that to show a proof that for that matrix \[A^T A = A A^T.\]
identity_matrix <- matrix(c(1,0,0,0,1,0,0,0,1),nrow = 3,ncol=3)
identity_matrix
## [,1] [,2] [,3]
## [1,] 1 0 0
## [2,] 0 1 0
## [3,] 0 0 1
t_identity_matrix <- t(identity_matrix)
t_identity_matrix
## [,1] [,2] [,3]
## [1,] 1 0 0
## [2,] 0 1 0
## [3,] 0 0 1
tim_im <- t_identity_matrix %*% identity_matrix
im_tim <- identity_matrix %*% t_identity_matrix
tim_im == im_tim
## [,1] [,2] [,3]
## [1,] TRUE TRUE TRUE
## [2,] TRUE TRUE TRUE
## [3,] TRUE TRUE TRUE
Write an R function to factorize a square matrix A into LU or LDU, whichever you prefer. Please submit your response in an R Markdown document using our class naming convention, E.g. LFulton_Assignment2_PS2.png
You don’t have to worry about permuting rows of A and you can assume that A is less than 5x5, if you need to hard-code any variables in your code. If you doing the entire assignment in R, then please submit only one markdown document for both the problems.
I’m struggling with this problem and will be reading more on how to solve this
library(matrixcalc) # for checking our work
# Function takes a matrix and returns the lower triangle decomposition
LU_factorize <- function(x) {
n_rows <- nrows(x)[1]
im_x <- diag(x)
}
lu.decomposition(rm)
## $L
## [,1] [,2] [,3]
## [1,] 1.0000000 0.0000000 0
## [2,] 2.1064772 1.0000000 0
## [3,] -0.9992073 -0.9271532 1
##
## $U
## [,1] [,2] [,3]
## [1,] 1.192519 -1.667013 0.3448809
## [2,] 0.000000 3.416264 1.2377678
## [3,] 0.000000 0.000000 0.6557617