Tachikawa17 Math refresher II

Andrei R. Akhmetzhanov

2017-08-06

Download RMarkdown file

Example 1

Calculate: \[ 3\left(\begin{array}{cc} 1 & 2 \\ 1 & 2 \end{array} \right) - \left(\begin{array}{cc} 3 & 2 \\ 3 & 2 \end{array} \right) - 4\left(\begin{array}{cc} 0 & 1 \\ 0 & 1 \end{array} \right). \] First we multiply the first and the third matrices on the scalars: \[ \left(\begin{array}{cc} 3 & 6 \\ 3 & 6 \end{array} \right) - \left(\begin{array}{cc} 3 & 2 \\ 3 & 2 \end{array} \right) - \left(\begin{array}{cc} 0 & 4 \\ 0 & 4 \end{array} \right). \] Then we sum up all matrices: \[ \left(\begin{array}{cc} 3-3-0 & 6-2-4 \\ 3-3-0 & 6-2-4 \end{array} \right)= \left(\begin{array}{cc} 0 & 0 \\ 0 & 0 \end{array} \right) \]

Example 3: Compute inverse matrix

First matrix

\[ \mathcal A = \left(\begin{array}{cc} 3 & 5 \\ 5 & 9 \end{array} \right) \] First, we calculate the determinant: \[ \det{\mathcal A} = \left|\begin{array}{cc} 3 & 5 \\ 5 & 9 \end{array} \right| = 3\times9-5\times5=27-25=2\,. \] Then we derive the adjoint matrix: \[ \mathrm{adj}(\mathcal A) = \left(\begin{array}{rr} 9 & -5 \\ -5 & 3 \end{array} \right)\,. \] Thus, we obtain: \[ \mathcal A^{-1} = \frac{\mathrm{adj}(\mathcal A)}{\det\mathcal A}=\left(\begin{array}{rr} 4.5 & -2.5 \\ -2.5 & 1.5 \end{array} \right) \]

Checking in R

# We define the matrix A
A = matrix(c(3,5,5,9), 2, 2, byrow = TRUE)
A
##      [,1] [,2]
## [1,]    3    5
## [2,]    5    9

We calculate the determinant:

det(A)
## [1] 2

Inverse matrix1 You can check the functions for matrix algebra in R: http://www.statmethods.net/advstats/matrix.html. Also, there is a quite helpful tutorial here: https://cran.r-project.org/web/packages/matlib/vignettes/eigen-ex1.html.

solve(A)
##      [,1] [,2]
## [1,]  4.5 -2.5
## [2,] -2.5  1.5

Second matrix

We have the 3x3 matrix: \[ \mathcal B = \left(\begin{array}{rrr} 2 & -1 & 0 \\ 0 & 2 & -1 \\ -1 & -1 & 1 \end{array}\right) \]

To get the inverse matrix, we first calculate the determinant: \[ \begin{split} \det\mathcal B &= \left|\begin{array}{rrr} 2 & -1 & 0 \\ 0 & 2 & -1 \\ -1 & -1 & 1 \end{array}\right| ={}\\ &\quad (-1)^{1+1}\cdot2\cdot\left|\begin{array}{rr} 2 & -1 \\ -1 & 1 \end{array}\right|+(-1)^{1+2}\cdot(-1)\cdot\left|\begin{array}{rr} 0 & -1 \\ -1 & 1 \end{array}\right|+ (-1)^{1+3}\cdot0\cdot\left|\begin{array}{rr} 0 & -1 \\ 2 & -1 \end{array}\right| = {} \\ &\quad 2\cdot1+1\cdot(-1)=1 \end{split} \] Then we calculate the adjoint matrix: \[ \mathrm{adj}(\mathcal B) = \left(\begin{array}{rrr} 1 & 1 & 2 \\ 1 & 2 & 3 \\ 1 & 2 & 4 \end{array}\right)^{\mathrm T} = \left(\begin{array}{rrr} 1 & 1 & 1 \\ 1 & 2 & 2 \\ 2 & 3 & 4 \end{array}\right) \] \(^{\mathrm T}\) denotes the matrix transposition.

This gives the inverse matrix in the form: \[ \mathcal B^{-1} = \frac{\mathrm{adj}(\mathcal B)}{\det\mathcal B} = \left(\begin{array}{rrr} 1 & 1 & 1 \\ 1 & 2 & 2 \\ 2 & 3 & 4 \end{array}\right) \]

Checking in R

# We define the matrix A
B = matrix(c(2,-1,0,0,2,-1,-1,-1,1), 3, 3, byrow = TRUE)
B
##      [,1] [,2] [,3]
## [1,]    2   -1    0
## [2,]    0    2   -1
## [3,]   -1   -1    1

We calculate the determinant:

det(B)
## [1] 1

Inverse matrix:

solve(B)
##      [,1] [,2] [,3]
## [1,]    1    1    1
## [2,]    1    2    2
## [3,]    2    3    4

Example 4: solve a system of two algebraic equations

Suppose that \(\mathbf{x}=(x_1 x_2)^{\mathrm T}\) is a vector of two unknown variables2 Here, the vector \(\mathbf{x}\) is a 2x1 matrix (2 rows and 1 column).. The question is how to find \(\mathbf x\), such that: \[ \mathcal A\mathbf{x} = b \] where \(\mathcal A\) is given by the previous example: \[ \mathcal A = \left(\begin{array}{cc} 3 & 5 \\ 5 & 9 \end{array} \right), \] and: \[ b = \left(\begin{array}{c} 2 \\ 4 \end{array}\right). \]

We simply multiply both sides of the system on \(\mathcal A^{-1}\) to obtain: \[ \mathcal A^{-1}\mathcal A\mathbf{x} = \mathcal A^{-1}b\,. \] Since \(\mathcal A^{-1}\mathcal A=E\), we obtain: Here E is the identity matrix. You can check: Ex = x. \[ \begin{split} \mathbf{x} = \mathcal A^{-1}&b = \left(\begin{array}{rr} 4.5 & -2.5 \\ -2.5 & 1.5 \end{array} \right)\cdot\left(\begin{array}{c} 2 \\ 4 \end{array}\right) \\ &\qquad {} = \left(\begin{array}{rr} 9 & -5 \\ -5 & 3 \end{array} \right)\cdot\left(\begin{array}{c} 1 \\ 2 \end{array}\right) = \left(\begin{array}{rr} 9\cdot1-5\cdot2 \\ -5\cdot1+3\cdot2 \end{array} \right) = \left(\begin{array}{rr} -1 \\ 1 \end{array} \right) \end{split} \]

Checking in R

b = matrix(c(2,4),2,1,byrow=TRUE)

# %*% denotes the matrix multiplication
solve(A)%*%b
##      [,1]
## [1,]   -1
## [2,]    1

Example 5a: calculate eigenvalues of the matrix

We have the matrix: \[ \mathcal A = \left(\begin{array}{rrr} 1 & -2 & -1 \\ -1 & 1 & 1 \\ 1 & 0 & 2 \end{array}\right) \] We need to calculate the determinant: \[ \det(\mathcal A-\lambda E) = \left|\begin{array}{ccc} 1-\lambda & -2 & -1 \\ -1 & 1-\lambda & 1 \\ 1 & 0 & 2-\lambda \end{array}\right|. \] If we use the third row to calculate the determinant, we get: \[ \begin{split} \det(\mathcal A-\lambda E) = (-2+(1-\lambda))+(2-\lambda)((1-\lambda)^2-2)=-1&{}-\lambda+(2-\lambda)(\lambda^2-2\lambda-1)=\\ &-1-\lambda+2\lambda^2-4\lambda-2-\lambda^3+2\lambda^2+\lambda \end{split} \] Finally, we get the polynomial of the form: \[ \det(\mathcal A-\lambda E) = -3-4\lambda+4\lambda^2-\lambda^3=0 \] This equation does not have nice roots, so we use R to calculate them.

Checking in R

A = matrix(c(1,-2,-1,-1,1,1,1,0,2),3,3,byrow=TRUE)
A
##      [,1] [,2] [,3]
## [1,]    1   -2   -1
## [2,]   -1    1    1
## [3,]    1    0    2

First we use eigen function to obtain the eigenvalues:

eigen(A)$values
## [1]  2.242792+1.071453i  2.242792-1.071453i -0.485584+0.000000i

Then we check that our polynomial gives the same values:

polyroot(c(-3,-4,4,-1))
## [1] -0.485584+0.000000i  2.242792+1.071453i  2.242792-1.071453i

As we see, it is what we have.

Example 5b: calculate eigenvalues of the matrix

We have the matrix: \[ \mathcal B = \left(\begin{array}{rrr} 2 & 1 & -3 \\ 3 & -2 & -3 \\ 1 & 1 & -2 \end{array}\right) \] We write: \[ \det(\mathcal B-\lambda E) = \left|\begin{array}{ccc} 2-\lambda & 1 & -3 \\ 3 & -2-\lambda & -3 \\ 1 & 1 & -2-\lambda \end{array}\right| \]

We use the last row to expand the determinant: \[ \det(\mathcal B-\lambda E) = \left|\begin{array}{cc} 1 & -3 \\ -2-\lambda & -3 \end{array}\right|-\left|\begin{array}{cc} 2-\lambda & -3 \\ 3 & -3 \end{array}\right|+(-2-\lambda)\left|\begin{array}{cc} 2-\lambda & 1 \\ 3 & -2-\lambda \end{array}\right| \]

We get: \[ \begin{split} \det(\mathcal B-\lambda E) = {}&-3(1\cdot1-1\cdot(-2-\lambda))+3((2-\lambda)\cdot1-1\cdot3)-(\lambda+2)((\lambda-2)(\lambda+2)-1\cdot3) = \\ &3(-1-2-\lambda+2-\lambda-3)-(\lambda+2)(\lambda^2-4-3) = {}& \\ &3\cdot(-2)(\lambda+2)-(\lambda+2)(\lambda^2-7) = {}& \\ &-(\lambda+2)(\lambda^2-1)=-(\lambda+2)(\lambda-1)(\lambda+1) \end{split} \]

We obtain three eigenvalues: \(-2\), \(\pm1\).

Checking in R

B = matrix(c(2,1,-3,3,-2,-3,1,1,-2),3,3,byrow=TRUE)
B
##      [,1] [,2] [,3]
## [1,]    2    1   -3
## [2,]    3   -2   -3
## [3,]    1    1   -2

We get:

eigen(B)$values
## [1] -2 -1  1

also we can obtain the eigenvectors:

eigen(B)$vectors
##            [,1]          [,2]      [,3]
## [1,]  0.5773503 -7.071068e-01 0.8164966
## [2,] -0.5773503  9.992007e-16 0.4082483
## [3,]  0.5773503 -7.071068e-01 0.4082483