diff --git a/cachematrix.R b/cachematrix.R index a50be65aa44..9590e6b1505 100644 --- a/cachematrix.R +++ b/cachematrix.R @@ -4,12 +4,30 @@ ## Write a short comment describing this function makeCacheMatrix <- function(x = matrix()) { - +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' + ## Return a matrix that is the inverse of 'x' s <- x$getsolve() + if(!is.null(s)) { + message("getting inversed matrix") + return(s) + } + data <- x$get() + s <- solve(data, ...) + x$setsolve(s) + s }