Skip to content

Instantly share code, notes, and snippets.

@qoelet
Created January 24, 2014 17:26
Show Gist options
  • Save qoelet/8601981 to your computer and use it in GitHub Desktop.
Save qoelet/8601981 to your computer and use it in GitHub Desktop.
# So R can solve linear algebra too!
lhs <- matrix(c(2, -1, 0, -1, 2, -3, 0, -1, 4), nrow=3)
"
[,1] [,2] [,3]
[1,] 2 -1 0
[2,] -1 2 -1
[3,] 0 -3 4
"
rhs <- matrix(c(0, -1, 4))
"
[,1]
[1,] 0
[2,] -1
[3,] 4
"
soln <- solve(lhs, rhs)
"
[,1]
[1,] 0
[2,] 0
[3,] 1
"
# prove it so
lhs %*% soln == rhs
"
[,1]
[1,] TRUE
[2,] TRUE
[3,] TRUE
"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment