diff --git a/cachematrix.R b/cachematrix.R index a50be65aa44..3547f813b40 100644 --- a/cachematrix.R +++ b/cachematrix.R @@ -3,13 +3,20 @@ ## Write a short comment describing this function -makeCacheMatrix <- function(x = matrix()) { - +makeCacheMatrix <- function() { +mat <- NULL +inv_cache <- NULL +setMatrix <- function(x) { +mat <<- x +inv_cache <<<- NULL +getInverse <- function() { +if (is.null(inv_cache)) { +inv_cache <<- solve(mat) } - - -## Write a short comment describing this function - -cacheSolve <- function(x, ...) { - ## Return a matrix that is the inverse of 'x' +inv_cache +list(setMatrix setMatrix, getInverse = getInverse) +} +cacheSolve <- function(x,...) { +inv_cache <- x$getInverse() +inv_cache }