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

#The original matrix

A<- matrix(c(1,2,3,4,-1,0,1,3,0,1,-2,1,5,4,-2,-3), nrow= 4, ncol=4, byrow= TRUE)
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
#Multiply the 1st row by -1 and subtract it from the 2nd row
A<- matrix(c(1,2,3,4,0,2,4,7,0,1,-2,1,5,4,-2,-3), nrow= 4, ncol=4, byrow= TRUE)
A
##      [,1] [,2] [,3] [,4]
## [1,]    1    2    3    4
## [2,]    0    2    4    7
## [3,]    0    1   -2    1
## [4,]    5    4   -2   -3
#Multiply the 1st row by 5  and subtract it from the 4th row 
A<- matrix(c(1,2,3,4,0,2,4,7,0,1,-2,1,0,-6,-17,-23), nrow= 4, ncol=4, byrow= TRUE)
A
##      [,1] [,2] [,3] [,4]
## [1,]    1    2    3    4
## [2,]    0    2    4    7
## [3,]    0    1   -2    1
## [4,]    0   -6  -17  -23
#Divide the 2nd row by 2 and subtract it from the 3rd row
A<- matrix(c(1,2,3,4,0,1,2,7/2,0,0,-4,-5/2,0,-6,-17,-23), nrow= 4, ncol=4, byrow= TRUE)
A
##      [,1] [,2] [,3]  [,4]
## [1,]    1    2    3   4.0
## [2,]    0    1    2   3.5
## [3,]    0    0   -4  -2.5
## [4,]    0   -6  -17 -23.0
#Multiply the 2nd row by -6 and subtract it from the 4th row
A<- matrix(c(1,2,3,4,0,1,2,7/2,0,0,-4,-5/2,0,0,-5,-2), nrow= 4 ,ncol=4, byrow= TRUE)
A
##      [,1] [,2] [,3] [,4]
## [1,]    1    2    3  4.0
## [2,]    0    1    2  3.5
## [3,]    0    0   -4 -2.5
## [4,]    0    0   -5 -2.0
#Restore the 2nd row to the original by multiplying it by 2
A<- matrix(c(1,2,3,4,0,2,4,7,0,0,-4,-5/2,0,0,-5,-2), nrow= 4, ncol=4, byrow= TRUE)
A
##      [,1] [,2] [,3] [,4]
## [1,]    1    2    3  4.0
## [2,]    0    2    4  7.0
## [3,]    0    0   -4 -2.5
## [4,]    0    0   -5 -2.0
#Divide the 3rd row by -4 and multiply the 3rd row by -5
A<- matrix(c(1,2,3,4,0,2,4,7,0,0,-5,-25/8,0,0,-5,-2), nrow= 4, ncol=4, byrow= TRUE)
A
##      [,1] [,2] [,3]   [,4]
## [1,]    1    2    3  4.000
## [2,]    0    2    4  7.000
## [3,]    0    0   -5 -3.125
## [4,]    0    0   -5 -2.000
#Subtract the 3rd row from the 4th row and divide 3rd row by -5
A<- matrix(c(1,2,3,4,0,2,4,7,0,0,1,5/8,0,0,0,9/8), nrow= 4, ncol=4, byrow= TRUE)
A
##      [,1] [,2] [,3]  [,4]
## [1,]    1    2    3 4.000
## [2,]    0    2    4 7.000
## [3,]    0    0    1 0.625
## [4,]    0    0    0 1.125
#Restore the 3rd row to the original view
A<- matrix(c(1,2,3,4,0,2,4,7,0,0,-4,-5/2,0,0,0,9/8), nrow= 4 ,ncol=4, byrow= TRUE)
A
##      [,1] [,2] [,3]   [,4]
## [1,]    1    2    3  4.000
## [2,]    0    2    4  7.000
## [3,]    0    0   -4 -2.500
## [4,]    0    0    0  1.125
#Calculate the number of linearly independent rows
A<- matrix(c(1,2,3,4,0,2,4,7,0,0,-4,-5/2,0,0,0,9/8), nrow= 4, ncol=4, byrow= TRUE)
A
##      [,1] [,2] [,3]   [,4]
## [1,]    1    2    3  4.000
## [2,]    0    2    4  7.000
## [3,]    0    0   -4 -2.500
## [4,]    0    0    0  1.125
# Since the reduced echelon matrix has four pivots and linearly independent, hence the Rank is 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?

#let A be an mxn matrix over field F. Then the row rank of A is equal
#to the maximum number of linear independent row vectors of A. hence 
#the row-rank of mxn matrix is at most n.

#Similarly, the column-rank of A is the maximum number of linear 
#independent columns of A. Hence the column-rank of A is at most m.

#Since for any matrix A mxn over field F, the row-rank = column-rank. Therefore
#to be the common value of row-rank A and column-rank A, clearly rank A has to be 
#equal or less of  Min (m,n) for any mxn matrix

# from the above, for any m x n matrix, if m is greater than n, then the maximum rank of the matrix is n.
# and if m is less than n, then the maximum rank of the matrix is m.

# The rank of a matrix would be zero only if the matrix had no elements. 
# However, If a matrix had even one element, its minimum rank would be one.

(3) What is the rank of matrix B?

# The original matrix 

B<- matrix(c(11,2,1,3,6,3,2,4,2), nrow=3, ncol=3, byrow=TRUE)
B
##      [,1] [,2] [,3]
## [1,]   11    2    1
## [2,]    3    6    3
## [3,]    2    4    2
# Multiply the 1st row by 3 and subtract it from the 2nd 
B<- matrix(c(1,2,1,0,0,0,2,4,2), nrow=3, ncol=3, byrow=TRUE)
B
##      [,1] [,2] [,3]
## [1,]    1    2    1
## [2,]    0    0    0
## [3,]    2    4    2
#Multiply the 1st row by 2 and subtract it from the 3rd row
B<- matrix(c(1,2,1,0,0,0,0,0,0), nrow=3, ncol=3, byrow=TRUE)
B
##      [,1] [,2] [,3]
## [1,]    1    2    1
## [2,]    0    0    0
## [3,]    0    0    0
#Calculate the number of linearly independent rows
B<- matrix(c(1,2,1,0,0,0,0,0,0), nrow=3, ncol=3, byrow=TRUE)
B
##      [,1] [,2] [,3]
## [1,]    1    2    1
## [2,]    0    0    0
## [3,]    0    0    0
# Hence the rank is 1.  

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.

# The original matrix 
A <- matrix(c(1,2,3,0,4,5,0,0,6), nrow=3, ncol = 3, byrow=TRUE)
A
##      [,1] [,2] [,3]
## [1,]    1    2    3
## [2,]    0    4    5
## [3,]    0    0    6
# To get the eigenvalues, we need to solve the determinant of of teh below matrxi:

col1<- c('1- lambda',0,3)
col2<- c(2,'4-lambda',0)
col3<- c(3,5,'6-lambda')

#Find the determinat of the below:
cbind(col1,col2,col3)
##      col1        col2       col3      
## [1,] "1- lambda" "2"        "3"       
## [2,] "0"         "4-lambda" "5"       
## [3,] "3"         "0"        "6-lambda"
#Which gives us the characteristic polynomial as
Det<- c(('-lambda^3)+11*lambda^2-34*lambda+24  = 0'))
Det 
## [1] "-lambda^3)+11*lambda^2-34*lambda+24  = 0"
# which factorizes as

Det <- c('-(lambda-1)(lambda-4)(lambda-6)')
Det
## [1] "-(lambda-1)(lambda-4)(lambda-6)"
# Which gives us Three eigenvalues as lambda1 =1, lambda2 = 4, or lambda3 =6.
# When you use lambda in the definition of eigenvalue, you get Av ??? lambdav = (A ??? lambda I)v = 0
when lambda1 = 1:
# The original matrix 
A <- matrix(c(1,2,3,0,4,5,0,0,6), nrow=3, ncol = 3, byrow=TRUE)
A
##      [,1] [,2] [,3]
## [1,]    1    2    3
## [2,]    0    4    5
## [3,]    0    0    6
##### when lambda1 = 1, we get: 

A<- matrix(c(0,2,3,0,3,5,0,0,5), nrow=3, ncol=3, byrow= TRUE)
A
##      [,1] [,2] [,3]
## [1,]    0    2    3
## [2,]    0    3    5
## [3,]    0    0    5
# devide row1 by row2

A<- matrix(c(0,1,3/2,0,3,5,0,0,5), nrow=3, ncol=3, byrow= TRUE)
A
##      [,1] [,2] [,3]
## [1,]    0    1  1.5
## [2,]    0    3  5.0
## [3,]    0    0  5.0
# substract 3 times row1 from row2
A<- matrix (c(0,1,3/2,0,0,1/2,0,0,5), nrow=3, ncol=3, byrow= TRUE)
A
##      [,1] [,2] [,3]
## [1,]    0    1  1.5
## [2,]    0    0  0.5
## [3,]    0    0  5.0
# devide row 2 by 1/2

A<- matrix(c(0,1,3/2,0,0,1,0,0,5), nrow=3, ncol=3, byrow= TRUE)
A
##      [,1] [,2] [,3]
## [1,]    0    1  1.5
## [2,]    0    0  1.0
## [3,]    0    0  5.0
# substract 5 times row 2 from row 3
A<- matrix(c(0,1,3/2,0,0,1,0,0,0), nrow=3, ncol=3, byrow= TRUE)
A
##      [,1] [,2] [,3]
## [1,]    0    1  1.5
## [2,]    0    0  1.0
## [3,]    0    0  0.0
# substrct 3/2 times row 2 from row 1
# final equation 
A<- matrix(c(0,1,0,0,0,1,0,0,0), nrow=3, ncol=3, byrow= TRUE)
A
##      [,1] [,2] [,3]
## [1,]    0    1    0
## [2,]    0    0    1
## [3,]    0    0    0
# Hence from the final equation above, for lambda1 =1,  we have x2 = 0, x3=0, and x1 = x1 ( x1 can be any variable).
# The eigenvector is ( x1, 0, 0)

###

when lambda2 = 4:

# The original matrix 
A <- matrix(c(1,2,3,0,4,5,0,0,6), nrow=3, ncol = 3, byrow=TRUE)
A
##      [,1] [,2] [,3]
## [1,]    1    2    3
## [2,]    0    4    5
## [3,]    0    0    6
#### when lambda2 = 4, we get:
A<- matrix (c(-3,2,3,0,0,5,0,0,2), nrow=3, ncol=3, byrow= TRUE)
A
##      [,1] [,2] [,3]
## [1,]   -3    2    3
## [2,]    0    0    5
## [3,]    0    0    2
# devide row1 by -3

A<- matrix(c(1,-2/3,-1,0,0,5,0,0,2), nrow=3, ncol=3, byrow= TRUE)
A
##      [,1]       [,2] [,3]
## [1,]    1 -0.6666667   -1
## [2,]    0  0.0000000    5
## [3,]    0  0.0000000    2
# devide row2 by 5

A<- matrix(c(1,-2/3,-1,0,0,1,0,0,2), nrow=3, ncol=3, byrow= TRUE)
A
##      [,1]       [,2] [,3]
## [1,]    1 -0.6666667   -1
## [2,]    0  0.0000000    1
## [3,]    0  0.0000000    2
# substract row2 times 2 from row3

A<- matrix(c(1,-2/3,-1,0,0,1,0,0,0), nrow=3, ncol=3, byrow= TRUE)
A
##      [,1]       [,2] [,3]
## [1,]    1 -0.6666667   -1
## [2,]    0  0.0000000    1
## [3,]    0  0.0000000    0
# substract -1 times row2 from row1

A<- matrix(c(1,-2/3,0,0,0,1,0,0,0), nrow=3, ncol=3, byrow= TRUE)
A
##      [,1]       [,2] [,3]
## [1,]    1 -0.6666667    0
## [2,]    0  0.0000000    1
## [3,]    0  0.0000000    0
# Hence from the final equation above, for lambda2 = 4,  we have x3=0, x1=2/3*x2, and x2 = x2.  
# The eigenvector is (2/3*x2, x2, 0)

####

for lambda3 = 6

# The original matrix 
A <- matrix(c(1,2,3,0,4,5,0,0,6), nrow=3, ncol = 3, byrow=TRUE)
A
##      [,1] [,2] [,3]
## [1,]    1    2    3
## [2,]    0    4    5
## [3,]    0    0    6
#### for lambda3 = 6, we get:

A<- matrix(c(-5,2,3,0,-2,5,0,0,0), nrow=3, ncol=3, byrow= TRUE)
A
##      [,1] [,2] [,3]
## [1,]   -5    2    3
## [2,]    0   -2    5
## [3,]    0    0    0
# Devide row1 by -5
A<- matrix(c(1,-2/5,-3/5,0,-2,5,0,0,0), nrow=3, ncol=3, byrow= TRUE)
A
##      [,1] [,2] [,3]
## [1,]    1 -0.4 -0.6
## [2,]    0 -2.0  5.0
## [3,]    0  0.0  0.0
# Devide row2 by -2

A<- matrix(c(1,-2/5,-3/5,0,1,-5/2,0,0,0), nrow=3, ncol=3, byrow= TRUE)
A
##      [,1] [,2] [,3]
## [1,]    1 -0.4 -0.6
## [2,]    0  1.0 -2.5
## [3,]    0  0.0  0.0
# substract -2/5 times row2 from row1 

A<- matrix(c(1,0,-8/5,0,1,-5/2,0,0,0), nrow=3, ncol=3, byrow= TRUE)
A
##      [,1] [,2] [,3]
## [1,]    1    0 -1.6
## [2,]    0    1 -2.5
## [3,]    0    0  0.0
# Hence from the final equation above, for lambda3 =6, x2=5/2*x3, x1=8/5*x3.
# The eigenvector is ( 8/5*x3, x2=5/2*x3, x3 )