From b261567a4e48e56ab3a44f23706d7a50322e59c3 Mon Sep 17 00:00:00 2001 From: RodHell Date: Sun, 22 Jun 2014 17:15:30 -0300 Subject: [PATCH] Prova2 --- cachematrix.R | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/cachematrix.R b/cachematrix.R index a50be65aa44..fd71d733938 100644 --- a/cachematrix.R +++ b/cachematrix.R @@ -1,15 +1,42 @@ ## Put comments here that give an overall description of what your ## functions do +##Try this: +## > a = c(2,3) +## > b = c(2,5) +## > abmatrix = matrix(c(a,b),byrow=TRUE,nrow=2) +## > mx <- makeCacheMatrix(abmatrix) +## > mx$get() +## > cacheSolve(mx) + ## Write a short comment describing this function +## This Function will return a matrix 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 +## This function will return the inverse of the first 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 }