A<-matrix(c(1,2,3,-1,0,4),2,3,byrow=TRUE)
A
## [,1] [,2] [,3]
## [1,] 1 2 3
## [2,] -1 0 4
X<-A%*%t(A)
X
## [,1] [,2]
## [1,] 14 11
## [2,] 11 17
Y<-t(A)%*%A
Y
## [,1] [,2] [,3]
## [1,] 2 2 -1
## [2,] 2 4 6
## [3,] -1 6 25
egx<-eigen(X)
egx
## eigen() decomposition
## $values
## [1] 26.601802 4.398198
##
## $vectors
## [,1] [,2]
## [1,] 0.6576043 -0.7533635
## [2,] 0.7533635 0.6576043
egy<-eigen(Y)
egy
## eigen() decomposition
## $values
## [1] 2.660180e+01 4.398198e+00 1.058982e-16
##
## $vectors
## [,1] [,2] [,3]
## [1,] -0.01856629 -0.6727903 0.7396003
## [2,] 0.25499937 -0.7184510 -0.6471502
## [3,] 0.96676296 0.1765824 0.1849001
svdA<-svd(A)
svdA
## $d
## [1] 5.157693 2.097188
##
## $u
## [,1] [,2]
## [1,] -0.6576043 -0.7533635
## [2,] -0.7533635 0.6576043
##
## $v
## [,1] [,2]
## [1,] 0.01856629 -0.6727903
## [2,] -0.25499937 -0.7184510
## [3,] -0.96676296 0.1765824
svdA$u
## [,1] [,2]
## [1,] -0.6576043 -0.7533635
## [2,] -0.7533635 0.6576043
egx$vectors
## [,1] [,2]
## [1,] 0.6576043 -0.7533635
## [2,] 0.7533635 0.6576043
svdA$v
## [,1] [,2]
## [1,] 0.01856629 -0.6727903
## [2,] -0.25499937 -0.7184510
## [3,] -0.96676296 0.1765824
egy$vectors
## [,1] [,2] [,3]
## [1,] -0.01856629 -0.6727903 0.7396003
## [2,] 0.25499937 -0.7184510 -0.6471502
## [3,] 0.96676296 0.1765824 0.1849001
svdA$d^2
## [1] 26.601802 4.398198
egx$values
## [1] 26.601802 4.398198
egy$values
## [1] 2.660180e+01 4.398198e+00 1.058982e-16
A<-matrix(c(1,0,3,1,3,1,1,2,1),nrow=3,byrow=TRUE)
myinverse<-function(x) {
cofactorm <- matrix(0,nrow=nrow(x),ncol=ncol(x),byrow=TRUE)
for (i in 1:ncol(x)) {
for (j in 1:nrow(x)) {
cofactorm[i,j] <- det(x[-i,-j])*(-1)^(i+j)
}
}
return(t(cofactorm)/det(x))
}
B<-myinverse(A)
B
## [,1] [,2] [,3]
## [1,] -0.5 -3 4.5
## [2,] 0.0 1 -1.0
## [3,] 0.5 1 -1.5
I<-A%*%B
I
## [,1] [,2] [,3]
## [1,] 1.000000e+00 -4.440892e-16 0.000000e+00
## [2,] -1.110223e-16 1.000000e+00 8.881784e-16
## [3,] -1.110223e-16 -2.220446e-16 1.000000e+00