review of linear algebra
play

Review of Linear Algebra Max Turgeon STAT 4690Applied Multivariate - PowerPoint PPT Presentation

Review of Linear Algebra Max Turgeon STAT 4690Applied Multivariate Analysis Basic Matrix operations 2 Matrix algebra and R Matrix operations in R are very fast. This includes various class of operations: Matrix addition, scalar


  1. Review of Linear Algebra Max Turgeon STAT 4690–Applied Multivariate Analysis

  2. Basic Matrix operations 2

  3. Matrix algebra and R • Matrix operations in R are very fast. • This includes various class of operations: • Matrix addition, scalar multiplication, matrix multiplication, matrix-vector multiplication • Standard functions like determinant, rank, condition number, etc. • Matrix decompositions, e.g. eigenvalue, singular value, Cholesky, QR, etc. • Support for sparse matrices, i.e. matrices where a signifjcant number of entries are exactly zero. 3

  4. Matrix functions i A <- matrix ( c (1, 2, 3, 4), nrow = 2, ncol = 2) A ## [,1] [,2] ## [1,] 1 3 ## [2,] 2 4 # Determinant det (A) ## [1] -2 4

  5. Matrix functions ii # Rank library (Matrix) rankMatrix (A) ## [1] 2 ## attr(,"method") ## [1] "tolNorm2" ## attr(,"useGrad") ## [1] FALSE ## attr(,"tol") ## [1] 4.440892e-16 5

  6. Matrix functions iii # Condition number kappa (A) ## [1] 18.77778 # How to compute the trace? sum ( diag (A)) ## [1] 5 6

  7. Matrix functions iv # Transpose t (A) ## [,1] [,2] ## [1,] 1 2 ## [2,] 3 4 # Inverse solve (A) 7

  8. Matrix functions v [,1] [,2] 1 0 ## [2,] 0 1 ## [1,] ## ## A %*% solve (A) # CHECK 1 -0.5 ## [2,] 1.5 -2 ## [1,] [,1] [,2] 8

  9. Matrix operations i A <- matrix ( c (1, 2, 3, 4), nrow = 2, ncol = 2) # Addition A + B ## [,1] [,2] ## [1,] 5 5 ## [2,] 5 5 9 B <- matrix ( c (4, 3, 2, 1), nrow = 2, ncol = 2)

  10. Matrix operations ii # Scalar multiplication 3 * A ## [,1] [,2] ## [1,] 3 9 ## [2,] 6 12 # Matrix multiplication A %*% B 10

  11. Matrix operations iii ## 4 6 ## [2,] 6 4 ## [1,] [,1] [,2] A * B ## # Hadamard product aka entrywise multiplication 8 20 ## [2,] 5 13 ## [1,] [,1] [,2] 11

  12. Matrix operations iv # Matrix-vector product vect <- c (1, 2) ## [,1] ## [1,] 7 ## [2,] 10 # BE CAREFUL: R recycles vectors A * vect 12 A %*% vect

  13. Matrix operations v ## [,1] [,2] ## [1,] 1 3 ## [2,] 4 8 13

  14. Eigenvalues and Eigenvectors 14

  15. Eigenvalues • The equation 15 • Let A be a square n × n matrix. det( A − λI n ) = 0 is called the characteristic equation of A . • This is a polynomial equation of degree n , and its roots are called the eigenvalues of A .

  16. Example Let Then we have 16    1 0 . 5  . A = 0 . 5 1 det( A − λI 2 ) = (1 − λ ) 2 − 0 . 25 = ( λ − 1 . 5)( λ − 0 . 5) Therefore, A has two (real) eigenvalues, namely λ 1 = 1 . 5 , λ 2 = 0 . 5 .

  17. A few properties nonnegative integer; 17 Let λ 1 , . . . , λ n be the eigenvalues of A (with multiplicities). 1. tr( A ) = ∑ n i =1 λ i ; 2. det( A ) = ∏ n i =1 λ i ; 3. The eigenvalues of A k are λ k 1 , . . . , λ k n , for k a 4. If A is invertible, then the eigenvalues of A − 1 are λ − 1 1 , . . . , λ − 1 n .

  18. Eigenvectors • In other words, the following equivalent statements hold: to the zero vector); nontrivial solution; 18 • If λ is an eigenvalues of A , then (by defjnition) we have det( A − λI n ) = 0 . • The matrix A − λI n is singular; • The kernel space of A − λI n is nontrivial (i.e. not equal • The system of equations ( A − λI n ) v = 0 has a • There exists a nonzero vector v such that A v = λv. • Such a vector is called an eigenvector of A .

  19. Example (cont’d) i Recall that we had We therefore have 19    1 0 . 5  , A = 0 . 5 1 and we determined that 0 . 5 was an eigenvalue of A .    0 . 5 0 . 5  . A − 0 . 5 I 2 = 0 . 5 0 . 5

  20. Example (cont’d) ii In other words, we not only get a single eigenvector, but a represensative a vector of norm 1, e.g. 20 As we can see, any vector v of the form ( x, − x ) satisfjes ( A − 0 . 5 I 2 ) v = (0 , 0) . whole subspace of R 2 . By convention, we usually select as a ( 1 ) 2 , − 1 √ √ v = . 2

  21. Example (cont’d) iii Alternatively, instead of fjnding the eigenvector by inspection, is given by 21 we can use the reduced row-echelon form of A − 0 . 5 I 2 , which    1 1  . A = 0 0 Therefore, the solutions to ( A − 0 . 5 I 2 ) v , with v = ( x, y ) are given by a single equation, namely y + x = 0 , or y = − x .

  22. Eigenvalues and eigenvectors in R i A <- matrix ( c (1, 0.5, 0.5, 1), nrow = 2) names (result) ## [1] "values" "vectors" result $ values ## [1] 1.5 0.5 22 result <- eigen (A)

  23. Eigenvalues and eigenvectors in R ii result $ vectors ## [,1] [,2] ## [1,] 0.7071068 -0.7071068 ## [2,] 0.7071068 0.7071068 1 /sqrt (2) ## [1] 0.7071068 23

  24. Symmetric matrices i eigenvalues are real. eigenvector corresponding to this eigenvalue. Then we have 24 • A matrix A is called symmetric if A T = A . • Proposition 1 : If A is (real) symmetric, then its Proof : Let λ be an eigenvalue of A , and let v ̸ = 0 be an

  25. Symmetric matrices ii 25 v T v = ¯ v T ( λv ) λ ¯ v T ( A v ) = ¯ = ( A T ¯ v ) T v v ) T v = ( A ¯ ( A is symmetric ) = ( A v ) T v ( A is real ) = ¯ v T v. λ ¯ Since we have v ̸ = 0 , we conclude that λ = ¯ λ , i.e. λ is real.

  26. Symmetric matrices iii eigenvectors corresponding to distinct eigenvalues are orthogonal. 26 • Proposition 2 : If A is (real) symmetric, then Proof : Let λ 1 , λ 2 be distinct eigenvalues, and let v 1 ̸ = 0 , v 2 ̸ = 0 be corresponding eigenvectors. Then we have

  27. orthogonal. Symmetric matrices iv 27 λ 1 v T 1 v 2 = ( A v 1 ) T v 2 = v T 1 A T v 2 = v T 1 A v 2 ( A is symmetric ) = v T 1 ( λ 2 v 2 ) = λ 2 v T 1 v 2 . Since λ 1 ̸ = λ 2 , we conclude that v T 1 v 2 = 0 , i.e. v 1 and v 2 are

  28. Spectral Decomposition i • Putting these two propositions together, we get the Spectral Decomposition for symmetric matrices. Sketch of a proof : 28 • Theorem : Let A be an n × n symmetric matrix, and let λ 1 ≥ · · · ≥ λ n be its eigenvalues (with multiplicity). Then there exist vectors v 1 , . . . , v n such that 1. A v i = λ i v i , i.e. v i is an eigenvector, for all i ; 2. If i ̸ = j , then v T i v j = 0 , i.e. they are orthogonal; 3. For all i , we have v T i v i = 1 , i.e. they have unit norm; 4. We can write A = ∑ n i =1 λ i v i v T i .

  29. Spectral Decomposition ii root of the characteristic polynomial), then the dimension of its eigenspace (i.e. the subspace of vectors satisfying Otherwise, fjnd a basis of the eigenspace and turn it into an orthogonal basis using the Gram-Schmidt algorithm. 3. This is one is straightforward: we are simply saying that we can choose the vectors so that they have unit norm. 29 1. We are saying that we can fjnd n eigenvectors. This means that if an eigenvalue λ has multiplicity m (as a A v = λv ) is also equal to m . This is not necessarily the case for a general matrix A . 2. If λ i ̸ = λ j , this is simply a consequence of Proposition 2.

  30. Then 4. is a consequence of the change of basis theorem: Spectral Decomposition iii if we change the basis from the standard one to 30 4. First, note that if Λ is a diagonal matrix with λ 1 , . . . , λ n on the diagonal, and P is a matrix whose i -th column is ∑ n i =1 λ i v i v T v i , then A = i is equivalent to A = P Λ P T . { v 1 , . . . , v n } , then A acts by scalar multiplication in each direction, i.e. it is represented by a diagonal matrix Λ .

  31. Examples i corresponding eigenvectors . and We looked at 31    1 0 . 5  , A = 0 . 5 1 and determined that the eigenvalues where 1 . 5 , 0 . 5 , with √ √ ( ) 1 / 2 , 1 / 2 √ √ ( ) 1 / 2 , − 1 / 2

  32. Examples ii v1 <- c (1 /sqrt (2), 1 /sqrt (2)) ## [,1] [,2] ## [1,] 1.0 0.5 ## [2,] 0.5 1.0 32 v2 <- c (1 /sqrt (2), -1 /sqrt (2)) Lambda <- diag ( c (1.5, 0.5)) P <- cbind (v1, v2) P %*% Lambda %*% t (P)

  33. Examples iii ## [1,] -0.2550974 -0.5047826 0.0953815 -0.5734243 0.2166169 ## [3,] 0.0953815 ## [2,] -0.5047826 -0.2792298 0.2166169 [,3] # Now let's look at a random matrix---- [,2] [,1] ## A A[ lower.tri (A)] <- A[ upper.tri (A)] # Let's make it symmetric A <- matrix ( rnorm (3 * 3), ncol = 3, nrow = 3) 33

  34. Examples iv ## [1,] -0.2550974 -0.5047826 0.0953815 -0.5734243 0.2166169 ## [3,] 0.0953815 ## [2,] -0.5047826 -0.2792298 0.2166169 [,3] result <- eigen (A, symmetric = TRUE) [,2] [,1] ## P <- result $ vectors 34 Lambda <- diag (result $ values) P %*% Lambda %*% t (P)

  35. Examples v # How to check if they are equal? all.equal (A, P %*% Lambda %*% t (P)) ## [1] TRUE 35

  36. Positive-defjnite matrices its (real) eigenvalues. positive semidefjnite . negative semidefjnite . 36 Let A be a real symmetric matrix, and let λ 1 ≥ · · · ≥ λ n be 1. If λ i > 0 for all i , we say A is positive defjnite . 2. If the inequality is not strict, if λ i ≥ 0 , we say A is 3. Similary, if λ i < 0 for all i , we say A is negative defjnite . 4. If the inequality is not strict, if λ i ≤ 0 , we say A is Note : If A is positive-defjnite , then it is invertible!

Recommend


More recommend