-
-
Save dirmeier/9dcdc3a79022628a606a6cec0976bb61 to your computer and use it in GitHub Desktop.
Matrix inverses
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
set.seed(23) | |
# Create a positive-definite matrix | |
# a Wishart random variable + the identity matrix should fullfil this. Any positive-definite matrix is invertible. | |
m <- rWishart(.1, 5, diag(5))[,,1] + diag(5) | |
# set the bottom and right to 1 | |
# by this the top left is positive definite, but the complete matrix is singular, i.e. not invertible | |
m[4:5, ] <- 1 | |
m[, 4:5] <- 1 | |
# works | |
solve(m[1:3, 1:3]) | |
# fails, due to rank deficiency | |
solve(m)[1:3, 1:3] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment