1.What is the rank of the matrix A?
library(pracma)
A <- matrix(c(1,2,3,4,-1,0,1,3,0,1,-2,1,5,4,-2,-3),byrow = TRUE,4,4)
A
## [,1] [,2] [,3] [,4]
## [1,] 1 2 3 4
## [2,] -1 0 1 3
## [3,] 0 1 -2 1
## [4,] 5 4 -2 -3
rref(A)#compute reduced row echelon form for matrix A, rank = # of non-zero rows
## [,1] [,2] [,3] [,4]
## [1,] 1 0 0 0
## [2,] 0 1 0 0
## [3,] 0 0 1 0
## [4,] 0 0 0 1
qr(A)$rank#verify rank using rank function
## [1] 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?
\(\because\) row rank of a matrix = column rank of the matrix,\(\therefore\) maximum rank of the matrix = min(m,n).
\(\because\) the matrix is non-zero, \(\therefore\) minimum rank of the matrix = 1.
3.What is the rank of matrix B?
B <- matrix(c(1,2,1,3,6,3,2,4,2),byrow = TRUE,3,3)
B
## [,1] [,2] [,3]
## [1,] 1 2 1
## [2,] 3 6 3
## [3,] 2 4 2
rref(B)
## [,1] [,2] [,3]
## [1,] 1 2 1
## [2,] 0 0 0
## [3,] 0 0 0
qr(B)$rank
## [1] 1
Through the observation of the matrix B, row 2 and 3 is 3 and 2 times of row 1 respectively, and would be eliminated through row operation. It’s obvious that rank(B)=1. (also verified through function used above)
Compute the eigenvalues and eigenvectors of matrix A.
matrixA <- matrix(c(1,2,3,0,4,5,0,0,6),byrow = TRUE,3,3)
matrixA
## [,1] [,2] [,3]
## [1,] 1 2 3
## [2,] 0 4 5
## [3,] 0 0 6
Compute characteristic polynomial and eigenvalues by hand
\(P_{A}\)(\(x\)) = \(det(\)A - \(x\) I\(_3\)) = \(det(\begin{bmatrix}1 & 2 & 3\\0 & 4 & 5\\0 & 0 & 6\end{bmatrix}\) - \(x\)\(\begin{bmatrix}1 & 0 & 0\\0 & 1 & 0\\0 & 0 & 1\end{bmatrix})\)
= \(det(\begin{bmatrix}1-x & 2 & 3\\0 & 4-x & 5\\0 & 0 & 6-x\end{bmatrix}\) = (1-\(x\)) \(det\begin{bmatrix}4-x & 5\\0 & 6-x\end{bmatrix}\) = (1-\(x\))(4-\(x\))(6-\(x\)) = -\(x^3\)+11\(x^2\)-34\(x\)+24
Eigenvalues: 1, 4, 6.
by built-in functions and function in Package pracma
-charpoly(matrixA,info = FALSE)
## [1] -1 11 -34 24
eigen(matrixA)$values
## [1] 6 4 1
Compute eigenvectors of matrix A for each eigenvalues For \(\lambda\) = 1,
matrix1 <- cbind((matrixA - 1*diag(3)),c(0,0,0))
matrix1
## [,1] [,2] [,3] [,4]
## [1,] 0 2 3 0
## [2,] 0 3 5 0
## [3,] 0 0 5 0
rref(matrix1)
## [,1] [,2] [,3] [,4]
## [1,] 0 1 0 0
## [2,] 0 0 1 0
## [3,] 0 0 0 0
\(x_2\)=0, \(x_3\)=0 \(\to\) \(c_1\) = \(\begin{bmatrix}1\\0\\0\end{bmatrix}\)
For \(\lambda\) = 4,
matrix4 <- cbind((matrixA - 4*diag(3)),c(0,0,0))
matrix4
## [,1] [,2] [,3] [,4]
## [1,] -3 2 3 0
## [2,] 0 0 5 0
## [3,] 0 0 2 0
rref(matrix4)
## [,1] [,2] [,3] [,4]
## [1,] 1 -0.6666667 0 0
## [2,] 0 0.0000000 1 0
## [3,] 0 0.0000000 0 0
\(x_1\)-\(\frac{2}{3}x_2\)=0, \(x_2\)=0 \(\to\) \(c_4\) = \(\begin{bmatrix}\frac{2}{3}\\1\\0\end{bmatrix}\)
For \(\lambda\) = 6,
matrix6 <- cbind((matrixA - 6*diag(3)),c(0,0,0))
matrix6
## [,1] [,2] [,3] [,4]
## [1,] -5 2 3 0
## [2,] 0 -2 5 0
## [3,] 0 0 0 0
rref(matrix6)
## [,1] [,2] [,3] [,4]
## [1,] 1 0 -1.6 0
## [2,] 0 1 -2.5 0
## [3,] 0 0 0.0 0
\(x_1\)-\(\frac{8}{5}x_3\)=0, \(x_2\)-\(\frac{5}{2}x_3\)=0 \(\to\) \(c_6\) = \(\begin{bmatrix}\frac{8}{5}\\\frac{5}{2}\\1\end{bmatrix}\)
c_1 <- c(1,0,0)
c_4 <- c(2/3,1,0)
c_6 <- c(8/5,5/2,1)
eigenvector <- cbind(c_6,c_4,c_1)
eigenvector
## c_6 c_4 c_1
## [1,] 1.6 0.6666667 1
## [2,] 2.5 1.0000000 0
## [3,] 1.0 0.0000000 0
eigen(matrixA)$vectors #compute eigenvector with built-in function
## [,1] [,2] [,3]
## [1,] 0.5108407 0.5547002 1
## [2,] 0.7981886 0.8320503 0
## [3,] 0.3192754 0.0000000 0