Added function to catch errors for non-exist inverse matrix or non-square original matrix