Problem Set 1

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

A_4x4 <- matrix(c(1,-1,0,5,2,0,1,4,3,1,-2,-2,4,3,1,-3),nrow=4,ncol=4)

#Option 1:

print(paste("Rank of Matrix:",rankMatrix(A_4x4)[1]))
## [1] "Rank of Matrix: 4"
diag(A_4x4)
## [1]  1  0 -2 -3
#option 2:
factor_output <- function(A) {
  
  L <- diag(nrow =dim(A)[1])
  
for(i in (1:dim(A)[1])) {
  for(j in (1:dim(A)[1])) {
    if(j<i) {
      Eliminate <- diag(nrow =dim(A)[1])

      if(A[i,j]>0) {
      Eliminate[i,j] <- -1*A[i,j]
      }
      else {Eliminate[i,j] <- A[i,j]
      }
              A <- Eliminate %*% A
              
L <- L %*% solve(Eliminate)  

      }
    }
}
print("Lower Matrix with 1 in all pivots. So the rank is 4.")
print(L)

} 


factor_output(matrix(c(1,-1,0,5,2,0,1,4,3,1,-2,-2,4,3,1,-3),nrow=4,ncol=4))
## [1] "Lower Matrix with 1 in all pivots. So the rank is 4."
##      [,1] [,2] [,3] [,4]
## [1,]    1    0    0    0
## [2,]    1    1    0    0
## [3,]    0    1    1    0
## [4,]    5    6    5    1

(2) Given an mxn matrix where m > n, what can be the maximum rank? The minimum rank, assuming that the matrix is non-zero?

For the \(mxn\) matrix which has m >n, the maximum rank will be 2. The minimum rank will be 1.

A_3x2 <- matrix(c(1,-1,0,5,2,0),nrow=3,ncol=2)

A_3x2_1 <- matrix(c(1,-1,1,-1,1,-1),nrow=3,ncol=2)


print(paste("Maximum Rank of Matrix:",rankMatrix(A_3x2)[1]))
## [1] "Maximum Rank of Matrix: 2"
print(paste("Minimum Rank of Matrix:",rankMatrix(A_3x2_1)[1]))
## [1] "Minimum Rank of Matrix: 1"

(3) What is the rank of matrix B?

B_3x3 = matrix(c(1,3,2,2,6,4,1,3,2),nrow=3,ncol=3)

print(paste("Maximum Rank of Matrix:",rankMatrix(B_3x3)[1]))
## [1] "Maximum Rank of Matrix: 1"

Because second column vector is the scalar multiple of first column vector. Third column vector is similar to first column vector.

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.

A_3x3 = matrix(c(1,0,0,2,4,0,3,5,6),nrow=3,ncol=3)
A_3x3
##      [,1] [,2] [,3]
## [1,]    1    2    3
## [2,]    0    4    5
## [3,]    0    0    6
I <- diag(dim(A_3x3)[1])

eigen(A_3x3)
## $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

$det(.I_n - A) = 0 $

\[ \left(\begin{array}{cc} \lambda-1 & -2 & -3\\ 0 & \lambda-4 & 0\\ 0 & 0 & \lambda-6\\ \end{array}\right) =0 \]

\((\lambda-1)(\lambda-4)(\lambda-6)-2(0)-3(0)-2(0)-(\lambda-1)(0)-3(0) = 0\)

Characteristic Equation: \((\lambda-1)(\lambda-4)(\lambda-6)=0\)

Eigen values from above Equation: \(\lambda = 1,4,6\)

Substitue \(\lambda=1\) on A

x=1

I <- diag(dim(A_3x3)[1])

A <- x*I-A_3x3


#For row 1,1

  for(i in (2:9)) {
  if(A[1,1]!=1 | A[1,1]!=-1){
    if(A[1,1]/i ==1 | A[1,1]/i ==-1) {
      A[1,] = A[1,]/i
    }
    else if (A[1,1]*i ==1 | A[1,1]*i ==-1) {
      A[1,] = A[1,]*i
    }
  } else {break}
}

#For Row 1,2
  
  for(i in (2:9)) {
  if(A[1,2]!=1 | A[1,2]!=-1){
    if(A[1,2]/i ==1 | A[1,2]/i ==-1) {
      A[1,] = A[1,]/i
    } 
    else if (A[1,2]*i ==1 | A[1,2]*i ==-1) {
      A[1,] = A[1,]*i
    }
   
  } else {break}
}

A[2,] = A[2,]+A[2,2]*A[1,]

#A[2,] = A[2,]*2

  for(i in (2:9)) {
  if(A[2,3]!=1 | A[2,3]!=-1){
    if(A[2,3]/i ==1 | A[2,3]/i ==-1) {
      A[2,] = A[2,]/i
    }
    else if (A[2,3]*i ==1 | A[2,3]*i ==-1) {
      A[2,] = A[2,]*i
    }
  } else {break}
}



A[3,] = A[3,]+A[3,3]*A[2,]
A[1,] = A[1,]+A[1,3]*A[2,]

print("Eigen Vector for eigen value 1:", A)
## [1] "Eigen Vector for eigen value 1:"
print(A)
##      [,1] [,2] [,3]
## [1,]    0   -1    0
## [2,]    0    0   -1
## [3,]    0    0    0

\[\lambda_1= \left(\begin{array}{cc} x_1\\ 0\\ 0\\ \end{array}\right) =0 \]

x=4

I <- diag(dim(A_3x3)[1])

A <- x*I-A_3x3

#For row 1,1

  for(i in (2:9)) {
  if(A[1,1]!=1 | A[1,1]!=-1){
    if(A[1,1]/i ==1 | A[1,1]/i ==-1) {
      A[1,] = A[1,]/i
    }
    else if (A[1,1]*i ==1 | A[1,1]*i ==-1) {
      A[1,] = A[1,]*i
    }
  } else {break}
}


#For Row 1,2
  
  for(i in (2:9)) {
  if(A[1,2]!=1 | A[1,2]!=-1){
    if(A[1,2]/i ==1 | A[1,2]/i ==-1) {
      A[1,] = A[1,]/i
    } 
    else if (A[1,2]*i ==1 | A[1,2]*i ==-1) {
      A[1,] = A[1,]*i
    }
   
  } else {break}
}


A[2,] = A[2,]+A[2,2]*A[1,]

#A[2,] = A[2,]*2

  for(i in (2:9)) {
  if(A[2,3]!=1 | A[2,3]!=-1){
    if(A[2,3]/i ==1 | A[2,3]/i ==-1) {
      A[2,] = A[2,]/i
    }
    else if (A[2,3]*i ==1 | A[2,3]*i ==-1) {
      A[2,] = A[2,]*i
    }
  } else {break}
}


A[3,] = A[3,]+A[3,3]*A[2,]
A[1,] = A[1,]+A[1,3]*A[2,]


print("Eigen Vector for eigen value 4:", A)
## [1] "Eigen Vector for eigen value 4:"
print(A)
##      [,1]       [,2] [,3]
## [1,]    1 -0.6666667    0
## [2,]    0  0.0000000   -1
## [3,]    0  0.0000000    0

\[\lambda_4= \left(\begin{array}{cc} 0.667x_2\\ x_2\\ 0\\ \end{array}\right) =0 \]

x=6

I <- diag(dim(A_3x3)[1])

A <- x*I-A_3x3


#For row 1,1

  for(i in (2:9)) {
  if(A[1,1]!=1 | A[1,1]!=-1){
    if(A[1,1]/i ==1 | A[1,1]/i ==-1) {
      A[1,] = A[1,]/i
    }
    else if (A[1,1]*i ==1 | A[1,1]*i ==-1) {
      A[1,] = A[1,]*i
    }
  } else {break}
}


#For row 2,2

  for(i in (2:9)) {
  if(A[2,2]!=1 | A[2,2]!=-1){
    if(A[2,2]/i ==1 | A[2,2]/i ==-1) {
      A[2,] = A[2,]/i
    }
    else if (A[3,3]*i ==1 | A[3,3]*i ==-1) {
      A[2,] = A[2,]*i
    }
  } else {break}
}

A[1,] = A[1,]-A[1,2]*A[2,]


print("Eigen Vector for eigen value 1:", A)
## [1] "Eigen Vector for eigen value 1:"
print(A)
##      [,1] [,2] [,3]
## [1,]    1    0 -1.6
## [2,]    0    1 -2.5
## [3,]    0    0  0.0

\[\lambda_6= \left(\begin{array}{cc} 1.6x_3\\ 2.5x_3\\ x_3\\ \end{array}\right) =0 \]