MATH319 Slides

169 Appendix B: R commands for matrices (continued)

A=[579-2],B=[123456]

> cbind(A,B) [forms matrix [AB] with A beside B]

> rbind(A,B) [forms matrix [(AB)] with A on top of B]

>A% *%B [forms the matrix product AB]

>A*X [multiplies matrices A and X, entry by entry]

>solve(A) [computes the inverse matrix of A]

>det(A) [computes the determinant of A]

>diag(A) [lists the entries of A on the leading diagonal]

>sum(diag(A)) [computes the trace of A]

>eigen(A) [computes the eigenvalues and eigenvectors of A]

>exp(A) [computes the matrix formed by exp of each entry of A]

>library(expm) [invokes the library expm for matrix exponential]

>expm(A) [computes the matrix exponential exp(A)]