code updated for matrix input and inverse