updated at Oct-12, added the function for calculating inverse matrix