Computing generalized inverses of a rational matrix and applications