diff --git a/cachematrix.R b/cachematrix.R index a50be65aa44..bfec70037bf 100644 --- a/cachematrix.R +++ b/cachematrix.R @@ -1,15 +1,26 @@ -## Put comments here that give an overall description of what your -## functions do - -## Write a short comment describing this function - -makeCacheMatrix <- function(x = matrix()) { - +makeCacheMatrix <- function(x = matrix()){ + inversa <- NULL + set <- function(y){ + x <<- y + inv <<- NULL + } + get <- function() {x} + setInverse <- function(inverse) {inversa <<- inverse} + getInverse <- function() {inversa} + list(set = set, + get = get, + setInverse = setInverse, + getInverse = getInverse) } - -## Write a short comment describing this function - -cacheSolve <- function(x, ...) { - ## Return a matrix that is the inverse of 'x' -} +cacheSolve <- function(x, ...){ + inversa <- x$getInverse() + if(!is.null(inversa)){ + message("getting cached data") + return(inversa) + } + matris <- x$get() + inversa <- solve(matris, ...) + x$setInverse(inversa) + inv +} \ No newline at end of file