Problem Set 1

In this problem, we’ll verify using R that SVD and Eigenvalues are related as worked out in the weekly module. Given a 3 × 2 matrix A:

\[ \begin{bmatrix} 1 & 2 & 3 \\ -1 & 0 & 4 \\ \end{bmatrix} \]

Write code in R to compute X = AA^T and Y = A^TA. Then, compute the eigenvalues and eigenvectors of X and Y using the built-in commands 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. Your code should compute all these vectors and scalars and store them in variables. Please add enough comments in your code to show me how to interpret your steps.

Write code in R to compute X and Y

##      [,1] [,2]
## [1,]   14   11
## [2,]   11   17
##      [,1] [,2] [,3]
## [1,]    2    2   -1
## [2,]    2    4    6
## [3,]   -1    6   25

Compute the left-singular, singular values, and right-singular vectors of A

##            [,1]       [,2]
## [1,] -0.6576043 -0.7533635
## [2,] -0.7533635  0.6576043
## [1] 5.157693 2.097188
##             [,1]       [,2]
## [1,]  0.01856629 -0.6727903
## [2,] -0.25499937 -0.7184510
## [3,] -0.96676296  0.1765824

Find the eigenvectors of X and Y

The eigenvectors of X and Y are similar to the left and right singular vectors of A.

##           [,1]       [,2]
## [1,] 0.6576043 -0.7533635
## [2,] 0.7533635  0.6576043
##             [,1]       [,2]       [,3]
## [1,] -0.01856629 -0.6727903  0.7396003
## [2,]  0.25499937 -0.7184510 -0.6471502
## [3,]  0.96676296  0.1765824  0.1849001

Find the square root eigenvalues of X and Y

The square roots of the eigenvalues of X and Y are equal to the singular vectors of X and Y.

## [1] 5.157693 2.097188
## [1] 5.157693e+00 2.097188e+00 7.393046e-09

Problem Set 2

Using the procedure outlined in section 1 of the weekly handout, write a function to compute the inverse of a well-conditioned full-rank square matrix using co-factors. In order to compute the co-factors, you may use built-in commands to compute the determinant. Your function should have the following signature: B = myinverse(A) where A is a matrix and B is its inverse and A×B = I. The off-diagonal elements of I should be close to zero, if not zero. Likewise, the diagonal elements should be close to 1, if not 1. Small numerical precision errors are acceptable but the function myinverse should be correct and must use co-factors and determinant of A to compute the inverse.

Cofactors of a matrix

A co-factor is the determinant of this sub-matrix along with the appropriate sign (+ or -) that goes with it.

##      [,1] [,2] [,3] [,4]
## [1,]   10    8   20   14
## [2,]    2   13   13   20
## [3,]   20   10    2    1
## [4,]    4    8   13    3
##            [,1]       [,2]        [,3]       [,4]
## [1,] -0.5018460  0.2900844 -0.41191983  0.5453586
## [2,]  1.1334388 -0.6165612 -0.28850211 -1.0828059
## [3,] -0.4525316  0.3829114  0.29588608 -0.5395570
## [4,] -0.3924051 -0.4018987  0.03639241  1.0000000