Matrix inversion using orthogonal polynomials