homework solved
doesn't work on singular matrices (doesn't chache that)