Created
October 20, 2011 01:32
-
-
Save smc77/1300192 to your computer and use it in GitHub Desktop.
Quick linear algebra demo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Matrix addition | |
matrix(c(1, 2, 3, 0, 5, 1), ncol=2) + matrix(c(4, 2, 0, 0.5, 5, 1), ncol=2) | |
# Matrix multiplication | |
3 * matrix(c(1, 2, 3, 0, 5, 1), ncol=2) | |
# Matrix-Vector Multiplication | |
matrix(c(1, 4, 2, 3, 0, 1), ncol=2) %*% c(1, 5) | |
# Matrix-Mector Multiplication | |
matrix(c(1, 2, 3, 0, 5, 1), ncol=2) %*% t(matrix(c(4, 2, 0, 0.5, 5, 1), ncol=2)) | |
# Transpose | |
t(matrix(c(4, 2, 0, 0.5, 5, 1), ncol=2)) | |
# Inverse | |
solve(matrix(c(4, 2, 0, 0.5, 5, 1), ncol=2)) | |
# Diagonal matrix * Inverse = Identity | |
diag(c(1, 2, 3)) * solve(diag(c(1, 2, 3))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment