library('matrixcalc')
library('pracma')

1.1

A = cbind(c(1,-1,0,5), c(2,0,1,4), c(3,1,-2,-2), c(4,3,1,-3))
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
# rank is number of pivots
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
# verify with Rank function
Rank(A)
## [1] 4
# Rank of matrix A is 4

1.2

# Matrix where m > n => more rows than columns
# max possible rank is min(m, n) == n
# min rank of non-zero matrix => at least one pivot so min rank 1

1.3

B = cbind(c(1,3,6), c(2,6,4), c(1,3,2))
rref(B) # 2 pivots
##      [,1] [,2] [,3]
## [1,]    1    0  0.0
## [2,]    0    1  0.5
## [3,]    0    0  0.0
# rank(B) is 2
Rank(B)
## [1] 2

2

\[ A = \begin{bmatrix} 1 & 2 & 3 \\ 0 & 4 & 5 \\ 0 & 0 & 6 \\ \end{bmatrix} \\ \text{Solve for eigenvalues:} \\ \det(A - \lambda I) = 0 \\ = \begin{vmatrix} 1 - \lambda & 2 & 3 \\ 0 & 4 - \lambda & 5 \\ 0 & 0 & 6 - \lambda \\ \end{vmatrix} \\ = (1 - \lambda) (4 - \lambda) (6 - \lambda) \\ \text{characteristic polynomial: } -\lambda^{3} + 11\lambda^{2} - 34\lambda + 24 \\ \lambda = 1, 4, 6 \\ \text{Solve for eigenvectors:} \\ (A - \lambda I)x = \textbf{0} \\ \lambda = 1: \\ \left( \begin{bmatrix} 1 & 2 & 3 \\ 0 & 4 & 5 \\ 0 & 0 & 6 \\ \end{bmatrix} - \begin{bmatrix} 1 & 0 & 0 \\ 0 & 1 & 0 \\ 0 & 0 & 1 \\ \end{bmatrix} \right) \begin{bmatrix} x_{1} \\ x_{2} \\ x_{3} \end{bmatrix} = \textbf{0} \\ \begin{bmatrix} 0 & 2 & 3 \\ 0 & 3 & 5 \\ 0 & 0 & 5 \\ \end{bmatrix} \begin{bmatrix} x_{1} \\ x_{2} \\ x_{3} \end{bmatrix}= \textbf{0} \\ rref \left( \begin{bmatrix} 0 & 2 & 3 \\ 0 & 3 & 5 \\ 0 & 0 & 5 \\ \end{bmatrix} \right) \implies \begin{bmatrix} 0 & 1 & 0 \\ 0 & 0 & 1 \\ 0 & 0 & 0 \\ \end{bmatrix} = \textbf{0} \\ x_{1}\text{ is free: } v_{1} = \begin{bmatrix} 1 \\ 0 \\ 0 \\ \end{bmatrix} \\ \lambda = 4: \\ \left( \begin{bmatrix} 1 & 2 & 3 \\ 0 & 4 & 5 \\ 0 & 0 & 6 \\ \end{bmatrix} - \begin{bmatrix} 4 & 0 & 0 \\ 0 & 4 & 0 \\ 0 & 0 & 4 \\ \end{bmatrix} \right) \begin{bmatrix} x_{1} \\ x_{2} \\ x_{3} \end{bmatrix} = \textbf{0} \\ \begin{bmatrix} -3 & 2 & 3 \\ 0 & 0 & 5 \\ 0 & 0 & 2 \\ \end{bmatrix} \begin{bmatrix} x_{1} \\ x_{2} \\ x_{3} \end{bmatrix}= \textbf{0} \\ rref \left( \begin{bmatrix} -3 & 2 & 3 \\ 0 & 0 & 5 \\ 0 & 0 & 2 \\ \end{bmatrix} \right) \implies \begin{bmatrix} 1 & -\frac{2}{3} & 0 \\ 0 & 0 & 1 \\ 0 & 0 & 0 \\ \end{bmatrix} = \textbf{0} \\ x_{2}\text{ is free: } v_{2} = \begin{bmatrix} \frac{2}{3} \\ 1 \\ 0 \\ \end{bmatrix} \text{, make unit length: } v_{2} = \begin{bmatrix} \frac{2}{3} \\ 1 \\ 0 \\ \end{bmatrix} \sqrt{1 + \frac{4}{9}} = \begin{bmatrix} 0.5547002 \\ 0.8320503 \\ 0 \\ \end{bmatrix} \\ \lambda = 6: \\ \left( \begin{bmatrix} 1 & 2 & 3 \\ 0 & 4 & 5 \\ 0 & 0 & 6 \\ \end{bmatrix} - \begin{bmatrix} 6 & 0 & 0 \\ 0 & 6 & 0 \\ 0 & 0 & 6 \\ \end{bmatrix} \right) \begin{bmatrix} x_{1} \\ x_{2} \\ x_{3} \end{bmatrix} = \textbf{0} \\ \begin{bmatrix} -5 & 2 & 3 \\ 0 & -2 & 5 \\ 0 & 0 & 0 \\ \end{bmatrix} \begin{bmatrix} x_{1} \\ x_{2} \\ x_{3} \end{bmatrix}= \textbf{0} \\ rref \left( \begin{bmatrix} -5 & 2 & 3 \\ 0 & -2 & 5 \\ 0 & 0 & 0 \\ \end{bmatrix} \right) \implies \begin{bmatrix} 1 & 0 & -1.6 \\ 0 & 1 & -2.5 \\ 0 & 0 & 0 \\ \end{bmatrix} = \textbf{0} \\ x_{3}\text{ is free: } v_{3} = \begin{bmatrix} 1.6 \\ 2.5 \\ 1 \\ \end{bmatrix} \text{, make unit length: } v_{3} = \begin{bmatrix} 1.6 \\ 2.5 \\ 1 \\ \end{bmatrix} \sqrt{2.56 + 6.25 + 1} = \begin{bmatrix} 0.5108407 \\ 0.7981886 \\ 0.3192754 \\ \end{bmatrix} \\ \text{eigenvectors and eigenvalues:} \begin{bmatrix} 0.5108407 & 0.5547002 & 1\\ 0.7981886 & 0.8320503 & 0\\ 0.3192754 & 0 & 0\\ \end{bmatrix} \begin{bmatrix} 6 \\ 4 \\ 1 \\ \end{bmatrix} \]

check with R

A = cbind(c(1,0,0), c(2,4,0), c(3,5,6))
A
##      [,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
# since charpoly = 0, just move to other side of equation to flip sign
charpoly(A)
## [1]   1 -11  34 -24