From b03852853176143297785b27bdc005e4fe3c647b Mon Sep 17 00:00:00 2001 From: Ricardo Manzano Date: Sun, 20 Apr 2014 01:25:39 +0200 Subject: [PATCH] First time working --- cachematrix.R | 35 ++++++++++++++++++++++++++++------- 1 file changed, 28 insertions(+), 7 deletions(-) diff --git a/cachematrix.R b/cachematrix.R index a50be65aa44..47cf997b265 100644 --- a/cachematrix.R +++ b/cachematrix.R @@ -1,15 +1,36 @@ -## Put comments here that give an overall description of what your -## functions do - -## Write a short comment describing this function +## Funtions in order to create the cacheMatrix list +## and the method that returns the cached inverse matrix +## Function that create list of matrix object makeCacheMatrix <- function(x = matrix()) { - + inv <- NULL + set <- function(y) { + x <<- y + inv <<- NULL + } + get <- function() x + setinverse <- function(inverse) inv <<- inverse + getinverse <- function() inv + list(set = set, get = get, + setinverse = setinverse, + getinverse = getinverse) } -## Write a short comment describing this function - +## Funcion that use the list matrix object to return cached inverse matrix cacheSolve <- function(x, ...) { ## Return a matrix that is the inverse of 'x' + inv <- x$getinverse() + if(!is.null(inv)) { + message("getting cached data") + return(inv) + } + data <- x$get() + inv <- solve(data, ...) + x$setinverse(inv) + inv } +#Testing +#x=makeCacheMatrix(matrix(c(1,0,0,1),2,2)) +#cacheSolve(x) +#cacheSolve(x) \ No newline at end of file