A <- Matrix::Matrix(
c(2, -1, 0, 0, -1, 2, -1, 0, 0, -1, 2, -1, 0, 0, -1, 2),
4,
4
)
# Partial inverse:
(S <- fm_qinv(A))
# Full inverse (not guaranteed to be symmetric):
(S2 <- solve(A))
# Matrix symmetry:
c(sum((S - Matrix::t(S))^2), sum((S2 - Matrix::t(S2))^2))
# Accuracy (not that S2 is non-symmetric, and S may be more accurate):
sum((S - S2)[S != 0]^2)
Run the code above in your browser using DataLab