From 6da8288bac6d49ab541c91fce37f0e503edd12da Mon Sep 17 00:00:00 2001 From: jsiska Date: Wed, 27 Jan 2016 18:44:23 +0100 Subject: [PATCH 1/2] Update cachematrix.R --- cachematrix.R | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/cachematrix.R b/cachematrix.R index a50be65aa44..3acf97e760c 100644 --- a/cachematrix.R +++ b/cachematrix.R @@ -4,12 +4,26 @@ ## Write a short comment describing this function makeCacheMatrix <- function(x = matrix()) { - + m_inv <- NULL + get <- function() x + setinv <- function(inverse) m_inv <<- inverse + getinv <- function() m_inv + list(get = get, + setinv = setinv, + getinv = getinv) } ## Write a short comment describing this function cacheSolve <- function(x, ...) { - ## Return a matrix that is the inverse of 'x' + m_inv <- x$getinv() + if(!is.null(m_inv)) { + message("getting cached data") + return(m_inv) + } + data <- x$get() + m_inv <- solve(data, ...) + x$setinv(m_inv) + m_inv } From 5137428b2b6e77c4342352333f69d90697bac5d6 Mon Sep 17 00:00:00 2001 From: jsiska Date: Wed, 27 Jan 2016 18:46:31 +0100 Subject: [PATCH 2/2] Update cachematrix.R --- cachematrix.R | 7 ------- 1 file changed, 7 deletions(-) diff --git a/cachematrix.R b/cachematrix.R index 3acf97e760c..38364ac46f3 100644 --- a/cachematrix.R +++ b/cachematrix.R @@ -1,8 +1,3 @@ -## Put comments here that give an overall description of what your -## functions do - -## Write a short comment describing this function - makeCacheMatrix <- function(x = matrix()) { m_inv <- NULL get <- function() x @@ -14,8 +9,6 @@ makeCacheMatrix <- function(x = matrix()) { } -## Write a short comment describing this function - cacheSolve <- function(x, ...) { m_inv <- x$getinv() if(!is.null(m_inv)) {