We will utilize the rref method from the pracma library to check our work.
library(pracma)
## Warning: package 'pracma' was built under R version 3.4.4
What is the rank of the matrix A?
According to https://www.cds.caltech.edu/~murray/wiki/What_is_matrix_rank_and_how_do_i_calculate_it%3F the rank of a matrix \(A\) is the number of independent columns of \(A\)
In addition, it states that the rank for a square matrix is considered full based on its determinant. If it is 0, then linearly dependent columns are present.
\[\mathbf{A} = \left[\begin{array} {rrr} 1 & 2 & 3 & 4\\ -1 & 0 & 1 & 3\\ 0 & 1 & -2 & 1\\ 5 & 4 & -2 & -3 \end{array}\right]\]
Using the det function from base R we calculated the determinant of the square matrix
cat("Matrix A","\n")
## Matrix A
(A <- matrix(c(1,2,3,4,
-1,0,1,3,
0,1,-2,1,
5,4,-2,-3),nrow=4, byrow=TRUE))
## [,1] [,2] [,3] [,4]
## [1,] 1 2 3 4
## [2,] -1 0 1 3
## [3,] 0 1 -2 1
## [4,] 5 4 -2 -3
cat("\n","The Determinant of Matrix A","\n")
##
## The Determinant of Matrix A
det(A)
## [1] -9
We see that the calculation is non-zero, therefore Matrix \(A\) is considered full rank, which means \(rk(A)=4\)
We have two ways to check to see if the rank is correct. First, using qr from base R.
cat("The Rank of Matrix A Using QR Base","\n")
## The Rank of Matrix A Using QR Base
qr(A)$rank
## [1] 4
In addition to qr, we can visualize the reduced row echelon form by implementing the rref function from the pracma package.
cat("The Reduced Row Echelon Form of Matrix A","\n")
## The Reduced Row Echelon Form of Matrix A
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
Based on this visualization, one can see that each row is independent of each other which classifies a full rank of 4.
Given an \(mxn\) matrix where \(m>n\), what can be the maximum rank? The minimum rank, assuming that the matrix is non-zero?
When m(rows) > n(columns) the maximum rank of the matrix is n(columns) and the minimum rank would at least be 1 because it is non-zero.
What is the rank of matrix B? \[\mathbf{B} = \left[\begin{array} {rrr} 1 & 2 & 1\\ 3 & 6 & 3\\ 2 & 4 & 2\\ \end{array}\right]\]
We will run the same test on matrix \(B\) as we did with matrix \(A\) to find out \(rk(B)\).
cat("Matrix B","\n")
## Matrix B
(B <- matrix(c(1,2,1,
3,6,3,
2,4,2),nrow=3, byrow=TRUE))
## [,1] [,2] [,3]
## [1,] 1 2 1
## [2,] 3 6 3
## [3,] 2 4 2
cat("\n","The Determinant of Matrix B","\n")
##
## The Determinant of Matrix B
det(B)
## [1] 0
The determinant of Matrix \(B\) is 0, therefore the \(rk(B)\) is 1.
cat("The Rank of Matrix B Using QR Base","\n")
## The Rank of Matrix B Using QR Base
qr(B)$rank
## [1] 1
cat("The Reduced Row Echelon Form of Matrix B","\n")
## The Reduced Row Echelon Form of Matrix B
rref(B)
## [,1] [,2] [,3]
## [1,] 1 2 1
## [2,] 0 0 0
## [3,] 0 0 0
Based off the visualization we see that Rows 2 & 3 are all 0’s with only Row 1 hosting non-zero values.
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. \[\mathbf{A} = \left[\begin{array} {rrr} 1 & 2 & 3\\ 0 & 4 & 5\\ 0 & 0 & 6\\ \end{array}\right]\]
Matrix \(A\) multiplied by the eigenvector \(x\) equals \(\lambda\) multiplied by the eigenvector \(x\)
\(A{\vec{x}}=\lambda{\vec{x}}\)
\(\lambda\) multiplied by the identity matrix is then subtracted from the matrix \(A\), and that calculation is equaled to 0.
\((A-\lambda I){\vec{x}}=0)\)
In addition, the determinant of the aforementioned statement is then equaled to 0, and this gives us our characteristic polynomial.
\(|(A-\lambda I){\vec{x}}|=0)\)
First let’s multiply \(\lambda\) by the identity matrix
\[\mathbf{I} = \left[\begin{array} {rrr} \lambda & 0 & 0\\ 0 & \lambda & 0\\ 0 & 0 & \lambda\\ \end{array}\right]\]
Next, we will subtract the identity matrix from matrix \(A\)
\(A=\left[ \begin{array}{c} 1 & 2 & 3 \\ 0 & 4 & 5 \\ 0 & 0 & 6 \end{array} \right] - \begin{bmatrix} \lambda & 0 & 0 \\ 0 & \lambda & 0 \\ 0 & 0 & \lambda \end{bmatrix} = \left[ \begin{array}{c} 1-\lambda & 2 & 3 \\ 0 & 4-\lambda & 5 \\ 0 & 0 & 6-\lambda \end{array} \right]\)
Our next step is to calculate the determinant of the 3x3 matrix. We will do this by using the Sarrus Rule which takes the first two columns of matrix \(A\) and appends them to the right of the matrix. \[\mathbf{A} = \left[\begin{array} {rrr} 1-\lambda & 2 & 3 & 1-\lambda & 2\\ 0 & 4-\lambda & 5 & 0 & 4-\lambda\\ 0 & 0 & 6-\lambda & 0 & 0\\ \end{array}\right]\]
Starting @ R1.1 we multiply diagonally down and add the products of R2.1 going down diagonally and R3.1 going down diagonally. Next starting at R5.1 we multiply diagonally to the left and subtract the products from R4.1 & $3.1 respectfully.
\([(1-\lambda)(4-\lambda)(6-\lambda)]+[(2)(5)(6-\lambda)]+[(3)(0)(0)]-[(2)(0)(6-\lambda)]-[(1-\lambda)(5)(0)]-[(3)(4-\lambda)(0)]\)
Which gives us the characteristic polynomial:
\((1-\lambda)(4-\lambda)(6-\lambda)=0\)
The eigenvalues are 1,4,6.
Let’s test the equations with each value:
Where \(\lambda=1\) \((1-1)(4-1)(6-1) = (0)(3)(5) = 0\)
Where \(\lambda=4\) \((1-4)(4-4)(6-4) = (-3)(0)(-2) = 0\)
Where \(\lambda=6\) \((1-6)(4-6)(6-6) = (-5)(-2)(0) = 0\)
In our final steps, we will check to see if our eigenvalues match the output from the eigen function in base R. This function will display the values as well as provide the eigenvectors for matrix \(A\)
(A <- matrix(c(1,2,3,
0,4,5,
0,0,6), nrow=3, byrow=TRUE))
## [,1] [,2] [,3]
## [1,] 1 2 3
## [2,] 0 4 5
## [3,] 0 0 6
eigen(A)
## eigen() decomposition
## $values
## [1] 6 4 1
##
## $vectors
## [,1] [,2] [,3]
## [1,] 0.5108407 0.5547002 1
## [2,] 0.7981886 0.8320503 0
## [3,] 0.3192754 0.0000000 0
Below, we will find the corresponding eigenvectors for matrix \(A\)
\[\mathbf{\lambda_1=1} \left[\begin{array} {rrr} 1\\ 0 \\ 0 \\ \end{array}\right]\]
\[\mathbf{\lambda_2=4} \left[\begin{array} {rrr} 0.5547002\\ 0.8320503 \\ 0 \\ \end{array}\right]\]
\[\mathbf{\lambda_3=6} \left[\begin{array} {rrr} 0.5108407\\ 0.7981886 \\ 0.3192754 \\ \end{array}\right]\]