#Matrix A
A <-matrix(c(-2,3,4,-1,2,6),nrow=3, ncol=2)
A
## [,1] [,2]
## [1,] -2 -1
## [2,] 3 2
## [3,] 4 6
#Transpose A
t(A)
## [,1] [,2] [,3]
## [1,] -2 3 4
## [2,] -1 2 6
#Matrix multplication of A traspose A
A %*% t(A)
## [,1] [,2] [,3]
## [1,] 5 -8 -14
## [2,] -8 13 24
## [3,] -14 24 52
#Matrix multiplication of A A transpose
t(A) %*% A
## [,1] [,2]
## [1,] 29 32
## [2,] 32 41
A <-matrix(c(2,0,0,-2),nrow=2, ncol=2)
A
## [,1] [,2]
## [1,] 2 0
## [2,] 0 -2
t(A)
## [,1] [,2]
## [1,] 2 0
## [2,] 0 -2
A %*% t(A)
## [,1] [,2]
## [1,] 4 0
## [2,] 0 4
t(A) %*% A
## [,1] [,2]
## [1,] 4 0
## [2,] 0 4
det(A)
## [1] -4
det(t(A))
## [1] -4
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.
library(matlib)
#MATRIX
a <- matrix(c(3,3,1,6,9,1,6,9,3), nrow=3, ncol=3)
a
## [,1] [,2] [,3]
## [1,] 3 6 6
## [2,] 3 9 9
## [3,] 1 1 3
#uPPER TRIANGLE FACTORING
b<-a
b[2,]<-(-1*b[1,]+b[2,]) #1*R1 + R2
b
## [,1] [,2] [,3]
## [1,] 3 6 6
## [2,] 0 3 3
## [3,] 1 1 3
b[3,]<-(-1/3*b[1,]+b[3,])#1/3R1 + R3
b
## [,1] [,2] [,3]
## [1,] 3 6 6
## [2,] 0 3 3
## [3,] 0 -1 1
b[3,]<-(1/3*b[2,]+b[3,])#1/3R2 + R3
b
## [,1] [,2] [,3]
## [1,] 3 6 6
## [2,] 0 3 3
## [3,] 0 0 2
#LOWER TRIANGLE
c<-matrix(c(1,0,0,1,1,0,.3,-.3,1),nrow=3,ncol=3, byrow=TRUE)
c
## [,1] [,2] [,3]
## [1,] 1.0 0.0 0
## [2,] 1.0 1.0 0
## [3,] 0.3 -0.3 1
b
## [,1] [,2] [,3]
## [1,] 3 6 6
## [2,] 0 3 3
## [3,] 0 0 2
round(c%*%b,0)
## [,1] [,2] [,3]
## [1,] 3 6 6
## [2,] 3 9 9
## [3,] 1 1 3
a
## [,1] [,2] [,3]
## [1,] 3 6 6
## [2,] 3 9 9
## [3,] 1 1 3