Problem 1

knitr::include_graphics('2-1.png')

1.1

knitr::include_graphics('2.1.1.png')

Now let’s prove that with R

A <- matrix(c(1,4,2,5,3,6), ncol=3)
identical(t(A) %*% A, A %*% t(A))
## [1] FALSE

Problem 2

knitr::include_graphics('2-2.png')

Creating function

fact = function(A){
  r <- c <- dim(A)[1]
  L <- D <- matrix(diag(r),nrow=r, ncol=c)
  U <- A
  for (j in 1:(c - 1)) {
    for (i in (j + 1):r) {
      L[i,j] <- U[i,j] / U[j,j]
      U[i,] <- U[i,] - U[j,] * L[i,j]
    }
  }
  diag(D) <- diag(U)
  for (k in 1:r) {
    U[k,] <- U[k,] / U[k,k]
  }
  LDU <- list("L" = L, "D" = D, "U" = U)
return(LDU)
}

The above chunk of codes made three matrices L, D and the matrix U= A.

rank=5
set.seed(1000)
x <- rnorm(rank^2)
A <- matrix(x, nrow=rank);A
##             [,1]        [,2]       [,3]        [,4]       [,5]
## [1,] -0.44577826 -0.38548930 -0.9824278  0.17005748  2.6700717
## [2,] -1.20585657 -0.47586788 -0.5544887  0.15507872 -1.2270160
## [3,]  0.04112631  0.71975069  0.1213812  0.02493187  0.8342473
## [4,]  0.63938841 -0.01850562 -0.1208723 -2.04658541  0.5325717
## [5,] -0.78655436 -1.37311776 -1.3360410  0.21315411 -0.6468250
LDU <- fact(A);LDU
## $L
##             [,1]      [,2]       [,3]        [,4] [,5]
## [1,]  1.00000000  0.000000  0.0000000  0.00000000    0
## [2,]  2.70505914  1.000000  0.0000000  0.00000000    0
## [3,] -0.09225733  1.206884  1.0000000  0.00000000    0
## [4,] -1.43431939 -1.007968 -0.2352282  1.00000000    0
## [5,]  1.76445201 -1.222325 -1.1837081 -0.01195647    1
## 
## $D
##            [,1]      [,2]      [,3]      [,4]      [,5]
## [1,] -0.4457783 0.0000000  0.000000  0.000000  0.000000
## [2,]  0.0000000 0.5669035  0.000000  0.000000  0.000000
## [3,]  0.0000000 0.0000000 -2.507375  0.000000  0.000000
## [4,]  0.0000000 0.0000000  0.000000 -2.013911  0.000000
## [5,]  0.0000000 0.0000000  0.000000  0.000000 -2.353956
## 
## $U
##      [,1]          [,2]         [,3]       [,4]        [,5]
## [1,]    1  8.647557e-01 2.203849e+00 -0.3814845  -5.9896856
## [2,]    0  1.000000e+00 3.709691e+00 -0.5378990 -14.9050381
## [3,]    0 -4.427829e-17 1.000000e+00 -0.1629769  -4.4980926
## [4,]    0 -6.809532e-17 0.000000e+00  1.0000000   0.7456815
## [5,]    0 -5.652513e-17 1.886565e-16  0.0000000   1.0000000