diff --git a/cachematrix.R b/cachematrix.R index a50be65aa44..ea6c03fbb8b 100644 --- a/cachematrix.R +++ b/cachematrix.R @@ -5,11 +5,32 @@ makeCacheMatrix <- function(x = matrix()) { +makeCacheMatrix <- function(x = numeric()) { + s <- NULL + set <- function(y) { + x <<- y + s <<- NULL + } + get <- function() x + setsolve <- function(solve) s <<- solve + getsolve <- function() s + list(set = set, get = get, + setsolve = setsolve, + getsolve = getsolve) } ## Write a short comment describing this function cacheSolve <- function(x, ...) { - ## Return a matrix that is the inverse of 'x' + cacheSolve <- function(x, ...) { + s <- x$getsolve() + if(!is.null(s)) { + message("getting cached data") + return(s) + } + data <- x$get() + s <- solve(data, ...) + x$setsolve(s) + s }