Algorithm to evaluate determinants and inverses of matrices