Matrix inversion caching

Matrix inversion caching