A. Linear Algebra

  1. FInd the Followings Corresponding to the given Matrix:

\[A = \begin{bmatrix} 1 \ \ 0 \ \ 0 \ \ 0 \\ 2 \ \ 3 \ \ 0 \ \ 0\\ 4 \ \ 5 \ \ 6 \ \ 0 \\ 7 \ \ 8 \ \ 9 \ \ 10\end{bmatrix}\] (a) Find the diagonal elements of the matrix A with proper R-command.

A = matrix(c(1,2,4,7,0,3,5,8,0,0,6,9,0,0,0,10), nrow=4)
A
##      [,1] [,2] [,3] [,4]
## [1,]    1    0    0    0
## [2,]    2    3    0    0
## [3,]    4    5    6    0
## [4,]    7    8    9   10
diag(A)
## [1]  1  3  6 10
  1. Find the eigen values of matrix A.
eigen(A)
## eigen() decomposition
## $values
## [1] 10  6  3  1
## 
## $vectors
##      [,1]       [,2]       [,3]       [,4]
## [1,]    0  0.0000000  0.0000000  0.6987881
## [2,]    0  0.0000000  0.4574957 -0.6987881
## [3,]    0  0.4061385 -0.7624929  0.1397576
## [4,]    1 -0.9138115  0.4574957 -0.0621145
  1. Do you see any similarity in answer (a) and (b)? If so, what is the similarity?

Yes, the Eigen value and the Diagonal are both the same, but the Eigen value is the reverse of the diagonal.

  1. Follow up question after (c): Is that relation between diagonal elements and eigen values of some matrix true for any matrix? You may have following situations:

    1. Yes, it is true for any matrix. I have verified with a few general matrices in RStudio

    2. No, the relation (c) is not true in general.

    If your answer is (d)-(ii), identify the matrix specification.

  1. No, the relation (c) is not true overall. I retried another matrix which did not have the same diagonal and eigen value. Basing my answer off of other examples of matrices I have tried, it seems that whenever you have a matrix that is zero’d out at the diagonal, the eigen value is always the same numbers, except in reverse. Because this is a 4x4 matrix, the process to find the determinate is more complicated, but the basic premise is still the same. Because half our matrix is already 0, the matrix basically flips giving us the reverse of our diagonal.
  1. Find \(A^{-1}\)
library(matlib)
## Warning: package 'matlib' was built under R version 3.4.4
## Warning in rgl.init(initValue, onlyNULL): RGL: unable to open X11 display
## Warning: 'rgl_init' failed, running with rgl.useNULL = TRUE
A
##      [,1] [,2] [,3] [,4]
## [1,]    1    0    0    0
## [2,]    2    3    0    0
## [3,]    4    5    6    0
## [4,]    7    8    9   10
A1 = inv(A)
A1
##             [,1]        [,2]       [,3] [,4]
## [1,]  1.00000000  0.00000000  0.0000000  0.0
## [2,] -0.66666667  0.33333333  0.0000000  0.0
## [3,] -0.11111111 -0.27777778  0.1666667  0.0
## [4,] -0.06666667 -0.01666667 -0.1500000  0.1
  1. Do you observe any pattern in \(A^{-1}\)? If so, report the pattern.
A1
##             [,1]        [,2]       [,3] [,4]
## [1,]  1.00000000  0.00000000  0.0000000  0.0
## [2,] -0.66666667  0.33333333  0.0000000  0.0
## [3,] -0.11111111 -0.27777778  0.1666667  0.0
## [4,] -0.06666667 -0.01666667 -0.1500000  0.1
A%*%A1
##        [,1]   [,2]  [,3] [,4]
## [1,]  1e+00  0e+00 0e+00    0
## [2,] -1e-08  1e+00 0e+00    0
## [3,] -1e-08 -3e-08 1e+00    0
## [4,] -5e-08 -8e-08 3e-08    1

The observation I have noticed is that the diagonal of the inverse is 1/1, 1/3, 1/6, and 1/10.

  1. Find the eigen values of \(A^{-1}\).
eigen(A1)
## eigen() decomposition
## $values
## [1] 1.0000000 0.3333333 0.1666667 0.1000000
## 
## $vectors
##            [,1]       [,2]       [,3] [,4]
## [1,]  0.6987881  0.0000000  0.0000000    0
## [2,] -0.6987881  0.4574957  0.0000000    0
## [3,]  0.1397576 -0.7624929  0.4061385    0
## [4,] -0.0621145  0.4574957 -0.9138115    1
  1. Do you see any relation between eigen values of A and eigen values of \(A^{-1}\)? If so, what is the relation?

[Help: For better understanding of the problem, you can consider a smaller version: \(A_{small} = \begin{bmatrix} 1 \ \ 0 \ \ 0 \\ 2 \ \ 3 \ \ 0 \\ 4 \ \ 5 \ \ 6\end{bmatrix}\)]

eigen(A)
## eigen() decomposition
## $values
## [1] 10  6  3  1
## 
## $vectors
##      [,1]       [,2]       [,3]       [,4]
## [1,]    0  0.0000000  0.0000000  0.6987881
## [2,]    0  0.0000000  0.4574957 -0.6987881
## [3,]    0  0.4061385 -0.7624929  0.1397576
## [4,]    1 -0.9138115  0.4574957 -0.0621145
eigen(A1)
## eigen() decomposition
## $values
## [1] 1.0000000 0.3333333 0.1666667 0.1000000
## 
## $vectors
##            [,1]       [,2]       [,3] [,4]
## [1,]  0.6987881  0.0000000  0.0000000    0
## [2,] -0.6987881  0.4574957  0.0000000    0
## [3,]  0.1397576 -0.7624929  0.4061385    0
## [4,] -0.0621145  0.4574957 -0.9138115    1
small = matrix(c(1,2,4,0,3,5,0,0,6), nrow=3)
small
##      [,1] [,2] [,3]
## [1,]    1    0    0
## [2,]    2    3    0
## [3,]    4    5    6
Es = eigen(small)

smallI =inv(small)
smallI
##            [,1]       [,2]      [,3]
## [1,]  1.0000000  0.0000000 0.0000000
## [2,] -0.6666667  0.3333333 0.0000000
## [3,] -0.1111111 -0.2777778 0.1666667
eigensI = eigen(smallI)

Es
## eigen() decomposition
## $values
## [1] 6 3 1
## 
## $vectors
##      [,1]       [,2]      [,3]
## [1,]    0  0.0000000  0.700140
## [2,]    0  0.5144958 -0.700140
## [3,]    1 -0.8574929  0.140028
eigensI
## eigen() decomposition
## $values
## [1] 1.0000000 0.3333333 0.1666667
## 
## $vectors
##           [,1]       [,2] [,3]
## [1,]  0.700140  0.0000000    0
## [2,] -0.700140  0.5144957    0
## [3,]  0.140028 -0.8574929    1

The only relation I have discovered between A and \(A^{-1}\) eigen values is that the the inverse eigen values are the fraction of matrix A’s eigen values, in reverse. If we took \(A^{-1}\) eigen values, flipped them, and multiplied them by matrix A’s, we would get the 1, 1, 1.

  1. Determine whether the following matrices are diagonalizable. If not, find the reason.
$$ (a) B_1 = \[\begin{bmatrix} 1 \ \ 0 \\ 0 \ \ 1 \end{bmatrix}\]
  1. B_2 = \[\begin{bmatrix} 0 \ \ 1 \\ 0 \ \ 1 \end{bmatrix}\]
  2. B_3 = \[\begin{bmatrix} 1 \ \ 0 \\ 0 \ \ 0 \end{bmatrix}\]
  3. B_4 = \[\begin{bmatrix} 0 \ \ 1 \\ 0 \ \ 0 \end{bmatrix}\] $$
B_1 = matrix(c(1,0,0,1), nrow=2)
B_2 = matrix(c(0,0,1,1), nrow=2)
B_3 = matrix(c(1,0,0,0), nrow=2)
B_4 = matrix(c(0,0,1,0), nrow=2)

B_1
##      [,1] [,2]
## [1,]    1    0
## [2,]    0    1
B_2
##      [,1] [,2]
## [1,]    0    1
## [2,]    0    1
B_3
##      [,1] [,2]
## [1,]    1    0
## [2,]    0    0
B_4
##      [,1] [,2]
## [1,]    0    1
## [2,]    0    0
det(eigen(B_1)$vectors)
## [1] 1
tol=10^{-10}

#a
if(abs(det(eigen(B_1)$vectors))<tol){stop("The matrix is not diagonalizable")}else{
D = diag(eigen(B_1)$values) 
P = eigen(B_1)$vectors 
P%*%D%*%solve(P)}
##      [,1] [,2]
## [1,]    1    0
## [2,]    0    1
#b
if(abs(det(eigen(B_2)$vectors))<tol){stop("The matrix is not diagonalizable")}else{
D = diag(eigen(B_2)$values) 
P = eigen(B_2)$vectors 
P%*%D%*%solve(P)}
##      [,1] [,2]
## [1,]    0    1
## [2,]    0    1
#c
if(abs(det(eigen(B_3)$vectors))<tol){stop("The matrix is not diagonalizable")}else{
D = diag(eigen(B_3)$values) 
P = eigen(B_3)$vectors 
P%*%D%*%solve(P)}
##      [,1] [,2]
## [1,]    1    0
## [2,]    0    0
#d
#if(abs(det(eigen(B_4)$vectors))<tol){stop("The matrix is not diagonalizable")}else{
#D = diag(eigen(B_4)$values) 
#P = eigen(B_4)$vectors 
#P%*%D%*%solve(P)}

\(B_4\) is not diagnolizable because if we took the eigen values and multiplied it by the diagonal of \(B_4\) it would not add up to the algebraic multiplication.

3.Solve the system of linear equations with four unknowns (Use R-commands only): \[x_1 = 1 \\ 2x_1 + 3x_2 = 2 \\ 4x_1 + 5x_2 + 6x_3 = 3 \\ 7x_1 + 8x_2 + 9x_3 +10x_4 = 4\]

T = matrix(c(1,0,0,0,2,3,0,0,4,5,6,0,7,8,9,10), nrow=4, ncol=4, byrow = TRUE)
T
##      [,1] [,2] [,3] [,4]
## [1,]    1    0    0    0
## [2,]    2    3    0    0
## [3,]    4    5    6    0
## [4,]    7    8    9   10
TI = matrix(c(1,2,3,4),byrow=TRUE)
TI
##      [,1]
## [1,]    1
## [2,]    2
## [3,]    3
## [4,]    4
showEqn(T,TI)
## 1*x1 + 0*x2 + 0*x3  + 0*x4  =  1 
## 2*x1 + 3*x2 + 0*x3  + 0*x4  =  2 
## 4*x1 + 5*x2 + 6*x3  + 0*x4  =  3 
## 7*x1 + 8*x2 + 9*x3 + 10*x4  =  4
solve(T,TI)
##               [,1]
## [1,]  1.000000e+00
## [2,] -4.857226e-17
## [3,] -1.666667e-01
## [4,] -1.500000e-01
  1. Solve the system of linear equations with four unknowns (Use R-commands only): \[x_1 = 1 \\ 2x_1 + 3x_2 = 2 \\ 4x_1 + 5x_2 + 6x_3 = 3 \\ 7x_1 + 8x_2 + 9x_3 = 4\]
F = matrix(c(1,0,0,2,3,0,4,5,6,7,8,9), nrow=4, ncol=3, byrow = TRUE)
F
##      [,1] [,2] [,3]
## [1,]    1    0    0
## [2,]    2    3    0
## [3,]    4    5    6
## [4,]    7    8    9
FI = matrix(c(1,2,3,4), byrow=TRUE)
FI
##      [,1]
## [1,]    1
## [2,]    2
## [3,]    3
## [4,]    4
showEqn(F,FI)
## 1*x1 + 0*x2 + 0*x3  =  1 
## 2*x1 + 3*x2 + 0*x3  =  2 
## 4*x1 + 5*x2 + 6*x3  =  3 
## 7*x1 + 8*x2 + 9*x3  =  4
#solve(F,FI)

If you have found a solution \(\begin{bmatrix} x_1 \\ x_2 \\ x_3 \\ x_4 \end{bmatrix}\), report that. If not, find the reason.

I have not found a solution to this system of equation because the matrix is not a square. Based on the way we have found solutions, the matrix seems to always be square. I believe there can be an estimate that can be found, but I am unfamiliar with the method.

  1. Use elementary row operations to find the \(A^{-1}\) corresponding to the given matrix in problem 1. That means show every single step (as output) for the transformation [A|I] ~ [I|\(A^{-1}\)]
AI = cbind(A,diag(4))
AI
##      [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8]
## [1,]    1    0    0    0    1    0    0    0
## [2,]    2    3    0    0    0    1    0    0
## [3,]    4    5    6    0    0    0    1    0
## [4,]    7    8    9   10    0    0    0    1
(AI[2,] = AI[2,]*2  - AI[3,])
## [1]  0  1 -6  0  0  2 -1  0
AI
##      [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8]
## [1,]    1    0    0    0    1    0    0    0
## [2,]    0    1   -6    0    0    2   -1    0
## [3,]    4    5    6    0    0    0    1    0
## [4,]    7    8    9   10    0    0    0    1
(AI[3,] = AI[3,] - 5)
## [1] -1  0  1 -5 -5 -5 -4 -5
AI
##      [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8]
## [1,]    1    0    0    0    1    0    0    0
## [2,]    0    1   -6    0    0    2   -1    0
## [3,]   -1    0    1   -5   -5   -5   -4   -5
## [4,]    7    8    9   10    0    0    0    1
(AI[4,] = AI[4,] - 9)
## [1] -2 -1  0  1 -9 -9 -9 -8
AI
##      [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8]
## [1,]    1    0    0    0    1    0    0    0
## [2,]    0    1   -6    0    0    2   -1    0
## [3,]   -1    0    1   -5   -5   -5   -4   -5
## [4,]   -2   -1    0    1   -9   -9   -9   -8
(AI[3,] = AI[1,]+AI[3,])
## [1]  0  0  1 -5 -4 -5 -4 -5
AI
##      [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8]
## [1,]    1    0    0    0    1    0    0    0
## [2,]    0    1   -6    0    0    2   -1    0
## [3,]    0    0    1   -5   -4   -5   -4   -5
## [4,]   -2   -1    0    1   -9   -9   -9   -8
(AI[3,] = AI[1,]+AI[3,])
## [1]  1  0  1 -5 -3 -5 -4 -5
AI
##      [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8]
## [1,]    1    0    0    0    1    0    0    0
## [2,]    0    1   -6    0    0    2   -1    0
## [3,]    1    0    1   -5   -3   -5   -4   -5
## [4,]   -2   -1    0    1   -9   -9   -9   -8
(AI[4,] = 2*AI[1,]+AI[4,])
## [1]  0 -1  0  1 -7 -9 -9 -8
AI
##      [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8]
## [1,]    1    0    0    0    1    0    0    0
## [2,]    0    1   -6    0    0    2   -1    0
## [3,]    1    0    1   -5   -3   -5   -4   -5
## [4,]    0   -1    0    1   -7   -9   -9   -8
(AI[4,] = AI[2,]+AI[4,])
## [1]   0   0  -6   1  -7  -7 -10  -8
AI
##      [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8]
## [1,]    1    0    0    0    1    0    0    0
## [2,]    0    1   -6    0    0    2   -1    0
## [3,]    1    0    1   -5   -3   -5   -4   -5
## [4,]    0    0   -6    1   -7   -7  -10   -8
(AI[3,] = AI[3,]-AI[1,])
## [1]  0  0  1 -5 -4 -5 -4 -5
AI
##      [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8]
## [1,]    1    0    0    0    1    0    0    0
## [2,]    0    1   -6    0    0    2   -1    0
## [3,]    0    0    1   -5   -4   -5   -4   -5
## [4,]    0    0   -6    1   -7   -7  -10   -8
(AI[3,] = 5*AI[4,]+AI[3,]) 
## [1]   0   0 -29   0 -39 -40 -54 -45
AI
##      [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8]
## [1,]    1    0    0    0    1    0    0    0
## [2,]    0    1   -6    0    0    2   -1    0
## [3,]    0    0  -29    0  -39  -40  -54  -45
## [4,]    0    0   -6    1   -7   -7  -10   -8
(AI[3,] = -(1/29)*AI[3,])
## [1] 0.000000 0.000000 1.000000 0.000000 1.344828 1.379310 1.862069 1.551724
AI
##      [,1] [,2] [,3] [,4]      [,5]     [,6]       [,7]      [,8]
## [1,]    1    0    0    0  1.000000  0.00000   0.000000  0.000000
## [2,]    0    1   -6    0  0.000000  2.00000  -1.000000  0.000000
## [3,]    0    0    1    0  1.344828  1.37931   1.862069  1.551724
## [4,]    0    0   -6    1 -7.000000 -7.00000 -10.000000 -8.000000
(AI[2,] = 6*AI[3,]+AI[2,])
## [1]  0.000000  1.000000  0.000000  0.000000  8.068966 10.275862 10.172414
## [8]  9.310345
AI
##      [,1] [,2] [,3] [,4]      [,5]     [,6]       [,7]      [,8]
## [1,]    1    0    0    0  1.000000  0.00000   0.000000  0.000000
## [2,]    0    1    0    0  8.068966 10.27586  10.172414  9.310345
## [3,]    0    0    1    0  1.344828  1.37931   1.862069  1.551724
## [4,]    0    0   -6    1 -7.000000 -7.00000 -10.000000 -8.000000
(AI[4,] = 6*AI[3,]+AI[4,])
## [1] 0.000000 0.000000 0.000000 1.000000 1.068966 1.275862 1.172414 1.310345
AI
##      [,1] [,2] [,3] [,4]     [,5]      [,6]      [,7]     [,8]
## [1,]    1    0    0    0 1.000000  0.000000  0.000000 0.000000
## [2,]    0    1    0    0 8.068966 10.275862 10.172414 9.310345
## [3,]    0    0    1    0 1.344828  1.379310  1.862069 1.551724
## [4,]    0    0    0    1 1.068966  1.275862  1.172414 1.310345