This pair of functions enables a user to cache the inverse of a matrix. There are two sets of functions:
makeCacheMatrix: This function creates a special "matrix" object that can cache its inverse.cacheSolve: This function computes the inverse of the special "matrix" returned bymakeCacheMatrixabove. If the inverse has already been calculated (and the matrix has not changed), thencacheSolveretrieves the inverse from the cache.
This function makes two assumptions:
- A square matrix has been input into the function
- The matrix supplied is always invertible.
This first function, makeCacheMatrix creates a special "matrix", which is
really a list containing a function to
- set the value of the matrix
- get the value of the matrix
- set the value of the inverse
- get the value of the inverse
The following function calculates the inverse of the special "matrix"
created with the above function. However, it first checks to see if the
inverse has already been calculated. If so, it gets the inverse from the
cache and skips the computation. Otherwise, it calculates the inverse of
the data and sets the value of the matrix inverse in the cache via the setsolve
function.