Write code in R to compute X = AAT and Y = ATA. Then, compute the eigenvaluesand eigenvectors of X and Y using the built-in commans in R. Then, compute the left-singular, singular values, and right-singular vectors of A using the svd command. Examine the two sets of singular vectors and show that they are indeed eigenvectors of X and Y. In addition, the two non-zero eigenvalues (the 3rd value will be very close to zero, if not zero) of both X and Y are the same and are squares of the non-zero singular values of A.
# COMPUTE X AND Y:
A<- matrix(c(1, -1, 2, 0, 3, 4), 2,3)
(X <-(A)%*%t(A))
## [,1] [,2]
## [1,] 14 11
## [2,] 11 17
(Y<- t(A)%*%(A))
## [,1] [,2] [,3]
## [1,] 2 2 -1
## [2,] 2 4 6
## [3,] -1 6 25
# COMPUTING EIGEN VALUES AND EIGEN VECTORS OF 'X' AND 'Y' :
(E_X <- eigen(X))
## eigen() decomposition
## $values
## [1] 26.601802 4.398198
##
## $vectors
## [,1] [,2]
## [1,] 0.6576043 -0.7533635
## [2,] 0.7533635 0.6576043
(E_Y<- eigen(Y))
## 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
# COMPUTE LEFT SINGULAR, SINGULAR, RIGHT SINGULAR OF 'A' USING "SVD" FUNCTION :
(left_singular_A <- svd(A)$u)
## [,1] [,2]
## [1,] -0.6576043 -0.7533635
## [2,] -0.7533635 0.6576043
(singular_A <- svd(A)$d)
## [1] 5.157693 2.097188
(right_singular_A <- svd(A)$v)
## [,1] [,2]
## [1,] 0.01856629 -0.6727903
## [2,] -0.25499937 -0.7184510
## [3,] -0.96676296 0.1765824