Created two routines for caching and solving a matrix.