A Method for Computing the Generalized Inverse of a Matrix