Efficient algorithm for computing inverse of parametric matrices