Problem Set 1

  1. Given a 3 × 2 matrix A write code in R to compute X = AAT and Y = ATA.

Matrix \(A\)

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

Matrix \(X=AA^T\)

##      [,1] [,2]
## [1,]   14   11
## [2,]   11   17

Matrix \(Y=A^TA\)

##      [,1] [,2] [,3]
## [1,]    2    2   -1
## [2,]    2    4    6
## [3,]   -1    6   25
  1. Then, compute the eigenvalues and eigenvectors of X and Y using the built-in commans in R.
compute the eigenvalues and eigenvectors of X and Y

Eigen Values for \(X\)

## [1] 26.6018  4.3982

Eigen Values for \(Y\)

## [1] 26.6018  4.3982  0.0000

Eigenvectors for \(X\)

##        [,1]    [,2]
## [1,] 0.6576 -0.7534
## [2,] 0.7534  0.6576

Eigenvectors for \(Y\)

##         [,1]    [,2]    [,3]
## [1,] -0.0186 -0.6728  0.7396
## [2,]  0.2550 -0.7185 -0.6472
## [3,]  0.9668  0.1766  0.1849
  1. Then, compute the left-singular, singular values, and right-singular vectors of A using the svd command.

Calculate SVD of \(A\)

Singular Values is $d below:

Left Vector is $u below:

Right Vector is $v below:

## $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
  1. 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.
## [1] 26.6018  4.3982
## [1] 26.6018  4.3982
## [1] 26.6018  4.3982  0.0000
## [1] 26.6018  4.3982  0.0000
## [1] 26.601802  4.398198

Problem Set 2

A function to compute the inverse of a well-conditioned full-rank square matrix using co-factors.

The function works by computing the co-factor matrix using : \(C_{ij} = (-1)^{i+j} det(M_{ij})\). The inverse matrix is then calculated using \(A^{-1}=\frac{C^T}{det(A)}\).

Demonstration

Let \(A=\begin{bmatrix} 1 & 6 & 7 \\2 & 5 & 8 \\ 3 & 6 & 9\end{bmatrix}\).

##       [,1] [,2]       [,3]
## [1,] -0.25   -1  1.0833333
## [2,]  0.50   -1  0.5000000
## [3,] -0.25    1 -0.5833333
##       [,1] [,2]       [,3]
## [1,] -0.25   -1  1.0833333
## [2,]  0.50   -1  0.5000000
## [3,] -0.25    1 -0.5833333
##      [,1] [,2] [,3]
## [1,] TRUE TRUE TRUE
## [2,] TRUE TRUE TRUE
## [3,] TRUE TRUE TRUE
##      [,1] [,2] [,3]
## [1,]    1    0    0
## [2,]    0    1    0
## [3,]    0    0    1