imlemented matrix with cached inverse