diff --git a/cachematrix.R b/cachematrix.R index a50be65aa44..211c9f88d8e 100644 --- a/cachematrix.R +++ b/cachematrix.R @@ -4,6 +4,15 @@ ## Write a short comment describing this function makeCacheMatrix <- function(x = matrix()) { + m <- NULL + set <- function(y){ + x <<- y + m <<- NULL + } + get<- function() x + setInverse <- function(Inverse) m <<- Inverse + getInverse <- function() m + list(set = set, get = get, setInverse = setInverse, getInverse = getInverse) } @@ -11,5 +20,14 @@ makeCacheMatrix <- function(x = matrix()) { ## Write a short comment describing this function cacheSolve <- function(x, ...) { + m <- x$getInverse() + if(!is.null(m)){ + message("getting cached data") + return(m) + } + data <- x$get() + m <- solve(data,...) + x$setInverse(m) + m ## Return a matrix that is the inverse of 'x' }