updated script to solve inverse matrix