Libraries used:

library(knitr)
## Warning: package 'knitr' was built under R version 3.5.3
library(matrixcalc)
library(png)

Problem Sets

imgage <- "C:/Users/jpsim/Documents/Computationial Math/4.png"
include_graphics(imgage)

Problem Set 1

Solution 1.a:

A <- matrix(c(1, -1, 2, 0, 3, 4), nrow=2)
A
##      [,1] [,2] [,3]
## [1,]    1    2    3
## [2,]   -1    0    4
X <- A%*%t(A)
Y <- t(A)%*%A
X
##      [,1] [,2]
## [1,]   14   11
## [2,]   11   17
Y
##      [,1] [,2] [,3]
## [1,]    2    2   -1
## [2,]    2    4    6
## [3,]   -1    6   25

Solution 1.b:

x <- eigen(X)
y <- eigen(Y)
x$val
## [1] 26.601802  4.398198
x$vec
##           [,1]       [,2]
## [1,] 0.6576043 -0.7533635
## [2,] 0.7533635  0.6576043
y$val
## [1] 2.660180e+01 4.398198e+00 1.058982e-16
y$vec
##             [,1]       [,2]       [,3]
## [1,] -0.01856629 -0.6727903  0.7396003
## [2,]  0.25499937 -0.7184510 -0.6471502
## [3,]  0.96676296  0.1765824  0.1849001

Solution 1.c:

asvd <- svd(A)
left <- asvd$u
left
##            [,1]       [,2]
## [1,] -0.6576043 -0.7533635
## [2,] -0.7533635  0.6576043
singular <- asvd$d
singular
## [1] 5.157693 2.097188
right <- asvd$v
right
##             [,1]       [,2]
## [1,]  0.01856629 -0.6727903
## [2,] -0.25499937 -0.7184510
## [3,] -0.96676296  0.1765824

Solution 1.d:

x$vec
##           [,1]       [,2]
## [1,] 0.6576043 -0.7533635
## [2,] 0.7533635  0.6576043
left
##            [,1]       [,2]
## [1,] -0.6576043 -0.7533635
## [2,] -0.7533635  0.6576043
y$vec
##             [,1]       [,2]       [,3]
## [1,] -0.01856629 -0.6727903  0.7396003
## [2,]  0.25499937 -0.7184510 -0.6471502
## [3,]  0.96676296  0.1765824  0.1849001
right
##             [,1]       [,2]
## [1,]  0.01856629 -0.6727903
## [2,] -0.25499937 -0.7184510
## [3,] -0.96676296  0.1765824

Solution 1.e:

5.16 * 5.16
## [1] 26.6256
2.1 * 2.1
## [1] 4.41

Problem Set 2

Solution:

myinverse <- function(A) {
  #  dimension and determinant of the matrix
 
  adim <- dim(A)[1]
  adet <- det(A)
 
  #co-matrix
  C <- A
  
  # Loop row
  for (i in 1: adim) {
    
    # Loop col
    for (j in 1: adim) {
       #  determinate for sub-matrix
       D <- A[-i, -j]
       ddet <- det(D)
       # Make  element
       C[i, j] <- (-1)^(i+j) * ddet
    }
  }
  B <- t(C)
  B <- B / adet
  return(B)
}
mat <- matrix(c(1, 2, 3, 1, 1, 1, 2, 0, 1),nrow=3)
mat
##      [,1] [,2] [,3]
## [1,]    1    1    2
## [2,]    2    1    0
## [3,]    3    1    1
invmat <- myinverse(mat)
invmat
##            [,1]       [,2]       [,3]
## [1,] -0.3333333 -0.3333333  0.6666667
## [2,]  0.6666667  1.6666667 -1.3333333
## [3,]  0.3333333 -0.6666667  0.3333333
invmat %*% mat
##               [,1]          [,2] [,3]
## [1,]  1.000000e+00  0.000000e+00    0
## [2,]  4.440892e-16  1.000000e+00    0
## [3,] -2.220446e-16 -5.551115e-17    1
solve(mat)
##            [,1]       [,2]       [,3]
## [1,] -0.3333333 -0.3333333  0.6666667
## [2,]  0.6666667  1.6666667 -1.3333333
## [3,]  0.3333333 -0.6666667  0.3333333