Homework Assignment Week 3
1. What is the rank of the matrix A?
\[A = \left[\begin{array}{rrrr} 1 & 2 & 3 & 4\\ -1 & 0 & 1 & 3\\ 0 & 1 & -2 & 1\\ 5 & 4 & -2 & -3\\ \end{array} \right] \]
Rank of a linear matrix is defined as: the number of linearly independent column vectors in the matrix.
require(Matrix)
require(pracma)
A <- matrix(c(1,-1,0,5,2,0,1,4,3,1,-2,-2,4,3,1,-3), ncol = 4, byrow = FALSE)
matA <- qr(A)
print("Matrix A in RREF Form: ")
## [1] "Matrix A in RREF 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
print("Matrix A rank: ")
## [1] "Matrix A rank: "
matA$rank
## [1] 4
As you can see, when matrix A is reduced to the RREF form, there are four non-zero columns, which we will designate as r = 4. As a result, the matrix is linearly independent. Therefore, given that r = 4 and the definition of rank, rank = 4.
2. Given an mxn matrix where m > n, what can be the maximum rank? The minimum rank, assuming that the matrix is non-zero?
The maximum number of linearly independent vectors in a matrix is equal to the number of non-zero rows in its row echelon matrix. Therefore, to find the rank of a matrix, we simply transform the matrix to its row echelon form and count the number of non-zero rows.
Therefore, the maximum rank can (when m > n) can only be n. The minimum rank for a non-zero matrix is 1. The rank can never be 0 as we already stated that we are only evaluating for non-zero matrices.
3. What is the rank of matrix B?
\[B = \left[\begin{array}{rrr} 1 & 2 & 1\\ 3 & 6 & 3\\ 2 & 4 & 2\\ \end{array} \right] \]
We will perform the same functions in R as we have done in question stem Number 1.
B <- matrix(c(1,3,2,2,6,4,1,3,2), ncol = 3, byrow = FALSE)
matB <- qr(B)
print("Matrix B in RREF Form: ")
## [1] "Matrix B in RREF Form: "
rref(B)
## [,1] [,2] [,3]
## [1,] 1 2 1
## [2,] 0 0 0
## [3,] 0 0 0
print("Matrix B rank: ")
## [1] "Matrix B rank: "
matB$rank
## [1] 1
In this particular example, the rank is equal to 1 for the same reasons as stated in question stem 1.
4. 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 work.
\[A = \left[\begin{array}{rrr} 1 & 2 & 3\\ 0 & 4 & 5\\ 0 & 0 & 6\\ \end{array} \right] \]
To determine the eigenvalues \(\lambda\) of A, we initially solve for the determinant of \(A - \lambda * I = 0\).
\[A - \lambda * I = \left[\begin{array}{rrr} 1 & 2 & 3\\ 0 & 4 & 5\\ 0 & 0 & 6\\\end{array} \right] - \lambda \left[\begin{array}{rrr} 1 & 0 & 0\\ 0 & 1 & 0\\ 0 & 0 & 1\\\end{array} \right] = \left[\begin{array}{rrr} 1-\lambda & 2 & 3\\ 0 & 4-\lambda & 5\\ 0 & 0 & 6-\lambda \\\end{array} \right]\]
\[ Determinant(A - \lambda * I) = \left|\begin{array}{ccc} 1-\lambda & 2 & 3\\ 0 & 4-\lambda & 5\\ 0 & 0 & 6-\lambda \\ \end{array} \right| = (-1)^2(1 - \lambda) \left|\begin{array}{cc} (4 - \lambda) & 5 \\ 0 & (6 - \lambda) \\ \end{array} \right| + (-1)^3(0)\left|\begin{array}{cc} 2 & 3 \\ 0 & (6 - \lambda) \\ \end{array} \right| + (-1)^4(0)\left|\begin{array}{cc} 2 & 3 \\ (4 - \lambda) & 5 \\ \end{array} \right|\]
This simplifies down to:
\[ Determinant(A - \lambda * I) = \left|\begin{array}{ccc} 1-\lambda & 2 & 3\\ 0 & 4-\lambda & 5\\ 0 & 0 & 6-\lambda \\ \end{array} \right| = (1 - \lambda) \left|\begin{array}{cc} (4 - \lambda) & 5 \\ 0 & (6 - \lambda) \\ \end{array} \right|\]
\[ Determinant(A - \lambda * I) = (1 -\lambda)[(4 - \lambda)(6 - \lambda) - (0)(5)] = (1-\lambda)(4-\lambda)(6-\lambda)\]
This is the roots of the characteristic polynomial.
\[(1-\lambda)(\lambda - 6)(\lambda - 4)\]
Now we can solve for \(\lambda\) aka the eigenvalues for matrix A.
\[\lambda = 6, 4, 1\]
Let’s confirm this with R.
A <- matrix(c(1,0,0,2,4,0,3,5,6), ncol = 3, byrow = FALSE)
eigen_A <- eigen(A)
print("The Eigenvalues of Matrix A: ")
## [1] "The Eigenvalues of Matrix A: "
eigen_A$values
## [1] 6 4 1
Also derived from the solution is the algebraic multiplicity which is simply the highest power of \((x - \lambda)\) that divides the characteristic polynomial, \(p_A(x)\). In this particular situation, for each eigenvalue of 6 and 4 and 1, its algebraic multiplicity = 1, 1, and 1 respectively.
Now to find the corresponding eigenvectors for the eigenvalues. In order to find the eigenvectors, we should look for the Null Space of \((A - \lambda * I)\) that corresponds to its eigenvalues, or in other words, find the eigenspace corresponding to its eigenvalue. To do this, we create a matrix of \((A - \lambda * I)\) and solve for the zero vector. The resulting vectors will be the eigenvectors.
Let’s start with eigenvalue = 6.
\[\epsilon_6 = \mathcal{N}(A - \lambda I_n)\] \[\mathcal{N}(A - \lambda I_n) = (A - \lambda I_n)x = 0\] As previously demonstrated:
\[(A - \lambda I_n) = \left[\begin{array}{rrr} 1-\lambda & 2 & 3\\ 0 & 4-\lambda & 5\\ 0 & 0 & 6-\lambda \\\end{array} \right]\]
If we substitute \(\lambda = 6\) into the above matrix, we will have:
\[(A - 6I_3) = \left[\begin{array}{rrr} -5 & 2 & 3\\ 0 & -2 & 5\\ 0 & 0 & 0 \\\end{array} \right]\]
Now we obtain the RREF of the matrix.
\[\left[\begin{array}{rrr} -5 & 2 & 3\\ 0 & -2 & 5\\ 0 & 0 & 0 \\\end{array} \right] -> R_2 + R_1 -> \left[\begin{array}{rrr} -5 & 0 & 8\\ 0 & -2 & 5\\ 0 & 0 & 0 \\\end{array} \right] -> (-1/5)R_1, (-1/2)R_2-> \left[\begin{array}{rrr} 1 & 0 & -8/5\\ 0 & 1 & -5/2\\ 0 & 0 & 0 \\\end{array} \right]\]
\(x_1 = (8/5)x_3\) and \(x_2 = (5/2)x_3\).
\(x_3\) is a free variable. Let’s assign \(x_3 = t\).
\[\epsilon_6 = span(\left[\begin{array}{r} 8/5 \\ 5/2 \\ 1 \\\end{array} \right]) = span(\left[\begin{array}{r} 16 \\ 25 \\ 10 \\\end{array} \right])\]
Let’s confirm this with R.
print("Confirm the eigenvectors for its corresponding eigenvalue of 6.")
## [1] "Confirm the eigenvectors for its corresponding eigenvalue of 6."
eigen_A$vectors[,1]
## [1] 0.5108407 0.7981886 0.3192754
print("Does this lie in the same plane (or similar) to our eigenvector(16, 25, 10)?")
## [1] "Does this lie in the same plane (or similar) to our eigenvector(16, 25, 10)?"
scalar_eig6 <- c(16,25,10)/(eigen_A$vectors[,1])
our_eig6_span <- c(16,25,10)
eigen_A$vectors[,1]*scalar_eig6 == our_eig6_span
## [1] TRUE TRUE TRUE
As you see, the computer confirms our answer.
Likewise, we will perform the same calculations for \(\epsilon_4\) and for \(\epsilon_1\). But for the sake of brevity (and given that I had explained all the steps on how to obtain an eigenvector), we will use R to help speed the process up.
For \(\epsilon_4\):
\[(A - 4I_3) = \left[\begin{array}{rrr} -3 & 2 & 3\\ 0 & 0 & 5\\ 0 & 0 & 2 \\\end{array} \right]\]
# Row Reduce this matrix
A_eig4 <- matrix(c(-3,0,0,2,0,0,3,5,2), ncol = 3, byrow = FALSE)
print("Row Reduced Matrix: ")
## [1] "Row Reduced Matrix: "
rref(A_eig4)
## [,1] [,2] [,3]
## [1,] 1 -0.6666667 0
## [2,] 0 0.0000000 1
## [3,] 0 0.0000000 0
print("Does this matrix[1,2] == -2/3? (This is important as we want to be as exact as possible) ")
## [1] "Does this matrix[1,2] == -2/3? (This is important as we want to be as exact as possible) "
rref(A_eig4)[1,2] == (-2/3)
## [1] TRUE
\(x_2\) is a free variable, \(x_3 = 0\), and \(x_1 = (2/3)x_2\).
Therefore, \(\epsilon_4 = span(\left[\begin{array}{r} 2/3 \\ 1 \\ 0 \\\end{array} \right])\)
And now for \(\epsilon_1\):
For \(\epsilon_1\):
\[(A - 1I_3) = \left[\begin{array}{rrr} 0 & 2 & 3\\ 0 & 3 & 5\\ 0 & 0 & 5 \\\end{array} \right]\]
# Row Reduce this matrix
A_eig1 <- matrix(c(0,0,0,2,3,0,3,5,5), ncol = 3, byrow = FALSE)
print("Row Reduced Matrix: ")
## [1] "Row Reduced Matrix: "
rref(A_eig1)
## [,1] [,2] [,3]
## [1,] 0 1 0
## [2,] 0 0 1
## [3,] 0 0 0
\(x_1\) is a free variable, \(x_2 = 0\), and \(x_3 = 0\).
Therefore, \(\epsilon_4 = span(\left[\begin{array}{r} 1 \\ 0 \\ 0 \\\end{array} \right])\)
Again, confirm with R.
print("Confirm the eigenvectors for its corresponding eigenvalue of 4.")
## [1] "Confirm the eigenvectors for its corresponding eigenvalue of 4."
eigen_A$vectors[,2]
## [1] 0.5547002 0.8320503 0.0000000
print("Does this lie in the same plane (or similar) to our eigenvector(2/3, 1, 0)?")
## [1] "Does this lie in the same plane (or similar) to our eigenvector(2/3, 1, 0)?"
scalar_eig4 <- c(2/3,1,0)/(eigen_A$vectors[,2])
our_eig4_span <- c(2/3,1,0)
eigen_A$vectors[,2]*scalar_eig4 == our_eig4_span
## [1] TRUE TRUE NA
As you noticed, the reason why we get ‘NA’ when we were trying to confirm the corresponding eigenvectors for eigenvalue of 4 is because we were trying to divide 0 over a 0, hence, returning an error. Otherwise, this vector is correct.
print("Confirm the eigenvectors for its corresponding eigenvalue of 1.")
## [1] "Confirm the eigenvectors for its corresponding eigenvalue of 1."
eigen_A$vectors[,3]
## [1] 1 0 0
print("Does this lie in the same plane (or similar) to our eigenvector(1, 0, 0)?")
## [1] "Does this lie in the same plane (or similar) to our eigenvector(1, 0, 0)?"
scalar_eig1 <- c(1,0,0)/(eigen_A$vectors[,3])
our_eig1_span <- c(1,0,0)
eigen_A$vectors[,3]*scalar_eig1 == our_eig1_span
## [1] TRUE NA NA
Again, like above, R is producing NAs as we cannot divide 0 over 0.
In conclusion, our eigenvalues are 6, 4, 1 with corresponding eigenvectors of \(\left[\begin{array}{r} 16 \\ 25 \\ 10 \\\end{array} \right], \left[\begin{array}{r} 2/3 \\ 1 \\ 0 \\\end{array} \right], \left[\begin{array}{r} 1 \\ 0 \\ 0 \\\end{array} \right]\).