diff --git a/cachematrix.R b/cachematrix.R new file mode 100644 index 0000000..52bfffc --- /dev/null +++ b/cachematrix.R @@ -0,0 +1,28 @@ +makeCacheMatrix <- function(x = matrix()) { + +inverse_x <- NULL +set <- function(y) { +x <<- y +inverse_x <<- NULL +} +get <- function() x +setinverse <- function(inverse) inverse_x <<- inverse +getinverse <- function() inverse_x +list(set = set, +get = get, +setinverse = setinverse , +getinverse = getinverse) + +} + +cacheSolve <- function(x, ...) { + inverse_x <- x$getinverse() + if(!is.null(inverse_x)) { + message("Getting cached data.") + return(inverse_x) + } + data <- x$get() + inverse_x <- solve(data) + x$setinverse(inverse_x) + inverse_x +}