calculation of cached matrix