From d640fdd5e7d472146eab0d648dc43eeeb55fe8f3 Mon Sep 17 00:00:00 2001 From: cad_rboliveira Date: Thu, 18 Jun 2015 08:10:00 -0300 Subject: [PATCH 1/2] editing file to include my solution for cached inversed matrix --- cachematrix.R | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/cachematrix.R b/cachematrix.R index a50be65aa44..71971b30ecc 100644 --- a/cachematrix.R +++ b/cachematrix.R @@ -4,7 +4,20 @@ ## Write a short comment describing this function makeCacheMatrix <- function(x = matrix()) { - + inversedM <- NULL + + set <- function(y) { + x <<- y + inversedM <<- NULL + } + + get <- function() x + + setInversed <- function(inversedM) inversedM <<- inversedM + + getInversed <- function() inversedM + + list(set = set, get = get, setInversed = setInversed, getInversed = getInversed) } @@ -12,4 +25,17 @@ makeCacheMatrix <- function(x = matrix()) { cacheSolve <- function(x, ...) { ## Return a matrix that is the inverse of 'x' + inverserd <- x$getInversed() + if (!is.null(inverserd)) { + message("getting cached data") + return(inverserd) + } + + matrix <- x$get() + + inversed <- solve(matrix) + + x$setInversed(inversed) + + inversed } From 2705f8a0dd2415d87f63e1f0fd63623200a4e204 Mon Sep 17 00:00:00 2001 From: Rafael Brito de Oliveira Date: Thu, 22 Oct 2015 10:55:58 -0200 Subject: [PATCH 2/2] commenting the code --- cachematrix.R | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/cachematrix.R b/cachematrix.R index 71971b30ecc..676aa187d4c 100644 --- a/cachematrix.R +++ b/cachematrix.R @@ -1,8 +1,8 @@ ## Put comments here that give an overall description of what your ## functions do -## Write a short comment describing this function - +## here the function mackeCacheMatrix, basically store the inversed matrix version +## to x makeCacheMatrix <- function(x = matrix()) { inversedM <- NULL @@ -21,8 +21,9 @@ makeCacheMatrix <- function(x = matrix()) { } -## Write a short comment describing this function - +## basically what it does here, is check if the x inversed matrix version is null +## if it is null, it creates through the solve function, a new matrix inversed and +## then set it to x inversed variable, if not, it just returns it cacheSolve <- function(x, ...) { ## Return a matrix that is the inverse of 'x' inverserd <- x$getInversed()