functions for getting/setting matrix and its inverse