From a4ad835ad59d08b2d0b0c3be8dd6cb1685eb3052 Mon Sep 17 00:00:00 2001 From: arkant05 Date: Mon, 21 Apr 2014 10:27:49 -0300 Subject: [PATCH] Update cachematrix.R --- cachematrix.R | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/cachematrix.R b/cachematrix.R index a50be65aa44..ced420a8cb9 100644 --- a/cachematrix.R +++ b/cachematrix.R @@ -1,15 +1,32 @@ -## Put comments here that give an overall description of what your -## functions do - -## Write a short comment describing this function +## Get a matrix and make a inverse cache of then makeCacheMatrix <- function(x = matrix()) { - + m <- NULL + set <- function(y) { + x <<- y + m <<- NULL + } + get <- function() x + setinvert <- function(solve) + m <<- solve + getinvert <- function() m + list(set = set, get = get, + setinvert = setinvert, + getinvert = getinvert) } -## Write a short comment describing this function +## If there is no Cache, return the inverse matrix cacheSolve <- function(x, ...) { - ## Return a matrix that is the inverse of 'x' + ## + m <- x$getinvert() + if(!is.null(m)) { + message("getting cached data") + return(m) + } + data <- x$get() + m <- solve(data) + x$setinvert(m) + m }