implemented matrix with cached inverse