- Problem set 2 Matrix factorization is a very important problem. There are supercomputers built just to do matrix factorizations. Every second you are on an airplane, matrices are being factorized. Radars that track ights use a technique called Kalman filtering. At the heart of Kalman Filtering is a Matrix Factorization operation. Kalman Filters are solving linear systems of equations when they track your ight using radars. 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.
factorize.function <- function(A)
{
n <- nrow(A)
L <- diag(n)
for(k in 1:(n-1))
{
for (i in (k+1):n) {
L[i,k] <- A[i,k]/A[k,k]
A[i,] <- A[i,] - L[i,k] * A[k,]
}
}
print("U is: ")
print(A)
print("L is: ")
print(L)
}
test1_matrix <- matrix(c(2,6,1,8), 2,2)
test1_matrix
## [,1] [,2]
## [1,] 2 1
## [2,] 6 8
factorize.function(test1_matrix)
## [1] "U is: "
## [,1] [,2]
## [1,] 2 1
## [2,] 0 5
## [1] "L is: "
## [,1] [,2]
## [1,] 1 0
## [2,] 3 1
test2_matrix <- matrix(c(1,2,3,1,1,1,2,0,1), 3,3)
test2_matrix
## [,1] [,2] [,3]
## [1,] 1 1 2
## [2,] 2 1 0
## [3,] 3 1 1
factorize.function(test2_matrix)
## [1] "U is: "
## [,1] [,2] [,3]
## [1,] 1 1 2
## [2,] 0 -1 -4
## [3,] 0 0 3
## [1] "L is: "
## [,1] [,2] [,3]
## [1,] 1 0 0
## [2,] 2 1 0
## [3,] 3 2 1