library(Matrix)
library(pracma)
## 
## Attaching package: 'pracma'
## The following objects are masked from 'package:Matrix':
## 
##     expm, lu, tril, triu

Problem Set 1

(1) What is the rank of the matrix A below?

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

A <- matrix(c(1, -2, 3, 4, -1, 0, 1, 3, 0, 1, -2, 1, 5, 4, -2, -3), 4, 4, byrow = TRUE)
qr(A)$rank
## [1] 4

A matrix’s rank is the number of linearly independent rows (or columns) - rows or columns which cannot be derived from each other. Rank is important in determining if we can solve a system of linear equations. If the rank equals the number of independent variables, then the matrix may be able to be used to find a unique solution.

Just to verify - one way to determine the number of linearly independent rows is to put the matrix into reduced row echelon form.

rref(A)
##      [,1] [,2] [,3] [,4]
## [1,]    1    0    0    0
## [2,]    0    1    0    0
## [3,]    0    0    1    0
## [4,]    0    0    0    1

The only solution is the trivial one, so matrix A is linearly indepenedent. Then rank of 4 is correct.

Alternatively, we can check if the matrix is “full rank” by looking for a non-zero determinant.

det(A)
## [1] 99

Thus, \(4 x 4\) matrix that’s full rank has rank of 4.

(2) Given an \(m x n\) matrix where \(m > n\), what can be the maximum rank? The minimum rank, assuming that the matrix is non-zero?

The maximum rank is n - the least of the number of rows and columns. A non-zero matrix will have a rank of at least 1. At least one row and column will be linearly independent if they’re not all zero.

(3) What is the rank of matrix B below?

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

B <- matrix(c(1, 2, 1, 3, 6, 3, 2, 4, 2), 3, 3, byrow = TRUE)
qr(B)$rank
## [1] 1

This makes sense - the second and third rows of the matrix can clearly be created by multiplying the first row by 3 or 2, respectively.

Problem set 2

Compute the eigenvalues and eigenvectors of the matrix A. You’ll need to show your work. You’ll need to write out the characteristic polynomial and show your solution.

\[ A = \begin{bmatrix} 1 & 2 & 3 \\ 0 & 4 & 5 \\ 0 & 0 & 6 \\ \end{bmatrix} \] We know \(A v = \lambda v\), where \(v\) is a vector, our eigenvector, and \(\lambda\) is a scalar, our eigenvalue.

To get the eigenvalue, we will get fancy. We throw in the identity matrix to turn the scalar into a vector. We’ll solve \(det(A - \lambda I_3)\), shown below: $$ \[\begin{bmatrix} 1 & 2 & 3 \\ 0 & 4 & 5 \\ 0 & 0 & 6 \\ \end{bmatrix}\]

$$

This gives us: \[ det( \begin{bmatrix} 1 - \lambda & 2 & 3 \\ 0 & 4 - \lambda & 5 \\ 0 & 0 & 6 - \lambda \\ \end{bmatrix}) = 0 \] \[ (1 - \lambda) * det( \begin{bmatrix} 4 - \lambda & 5 \\ 0 & 6 - \lambda \\ \end{bmatrix}) - 2 * det( \begin{bmatrix} 0 & 5 \\ 0 & 6 - \lambda \\ \end{bmatrix}) + 3 * det( \begin{bmatrix} 0 & 4 - \lambda \\ 0 & 0\\ \end{bmatrix}) = 0 \]

\[ (1 - \lambda)(4 - \lambda)(6 - \lambda) - 2(0) + 3(0) = 0 \] Solving the polynomial for 0 gives us eigenvalues of 1, 4, and 6.

Let’s verify using R.

A <- matrix(c(1, 2, 3, 0, 4, 5, 0, 0, 6), 3, 3, byrow = TRUE)
eigen(A)$values
## [1] 6 4 1

Now the eigenvectors. Plug the eigenvalues back into the \(A v = \lambda v\) equation. \[ A - 6I_3 = \begin{bmatrix} -5 & 2 & 3 \\ 0 & -2 & 5 \\ 0 & 0 & 0 \\ \end{bmatrix} \]

Get this into reduced row echelon form and determine what vector makes it 0: \[ \begin{bmatrix} 1 & 0 & -8/5 \\ 0 & 1 & -5/2 \\ 0 & 0 & 0 \\ \end{bmatrix} \begin{bmatrix} v_1 \\ v_2 \\ v_3 \\ \end{bmatrix} = \begin{bmatrix} 0 \\ 0 \\ 0 \\ \end{bmatrix} \]

Finally, we get the following eigenvector for \(\lambda\) for eigenvalue 6: \[ \begin{bmatrix} 8/5 \\ 5/2 \\ 1 \\ \end{bmatrix} \]

We’ll skip a step for the other eigenvalues.

\[ A - 4I_3 = \begin{bmatrix} -3 & 2 & 3 \\ 0 & 0 & 5 \\ 0 & 0 & 2 \\ \end{bmatrix} \] Eigenvector for eigenvalue 4: \[ \begin{bmatrix} 2/3 \\ 1 \\ 0 \\ \end{bmatrix} \]

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

Eigenvector for eigenvalue 4: \[ \begin{bmatrix} 1 \\ 0 \\ 0 \\ \end{bmatrix} \]

Finally, we’ll verify the R-calculated eigenvectors:

eigen(A)$vectors
##           [,1]      [,2] [,3]
## [1,] 0.5108407 0.5547002    1
## [2,] 0.7981886 0.8320503    0
## [3,] 0.3192754 0.0000000    0

Ratios match our calculated values.

References:

https://stackoverflow.com/questions/10881392/rank-of-a-matrix-in-r