From 5948e116259f54e6499cd2faca73be07fdf462a8 Mon Sep 17 00:00:00 2001 From: Marshall Westfall Date: Sat, 26 Sep 2015 17:33:36 -0500 Subject: [PATCH 1/2] Update cachematrix.R --- cachematrix.R | 34 ++++++++++++++++++++++++++++------ 1 file changed, 28 insertions(+), 6 deletions(-) diff --git a/cachematrix.R b/cachematrix.R index a50be65aa44..62ae7f6c669 100644 --- a/cachematrix.R +++ b/cachematrix.R @@ -1,15 +1,37 @@ -## Put comments here that give an overall description of what your -## functions do +## cachematrix.R +## +## Create a cache marix object in order +## to increase performance by not have +## to calculate repeatedly -## Write a short comment describing this function +## Creates cacheMatrix object makeCacheMatrix <- function(x = matrix()) { - + cachedInverse <- NULL + set <- function(y) { + x <<- y + cachedInverse <<- NULL + } + get <- function() x + setInverse <- function(inverse) cachedInverse <<- inverse + getInverse <- function() cachedInverse + list(set = set, get = get, + setInverse = setInverse, + getInverse = getInverse) } -## Write a short comment describing this function +## Returns the inverse cacheMatrix object cacheSolve <- function(x, ...) { - ## Return a matrix that is the inverse of 'x' + ## Return a matrix that is the inverse of 'x' + invFunc <- x$getInverse() + if(!is.null(invFunc)) { + message("getting cached data") + return(invFunc) + } + data <- x$get() + invFunc <- solve(data, ...) + x$setInverse(invFunc) + invFunc } From a3404149faed3f16d64be2a92647315b652a02da Mon Sep 17 00:00:00 2001 From: Marshall Westfall Date: Sat, 26 Sep 2015 17:39:55 -0500 Subject: [PATCH 2/2] Update cachematrix.R --- cachematrix.R | 2 -- 1 file changed, 2 deletions(-) diff --git a/cachematrix.R b/cachematrix.R index 62ae7f6c669..83414964b91 100644 --- a/cachematrix.R +++ b/cachematrix.R @@ -5,7 +5,6 @@ ## to calculate repeatedly ## Creates cacheMatrix object - makeCacheMatrix <- function(x = matrix()) { cachedInverse <- NULL set <- function(y) { @@ -22,7 +21,6 @@ makeCacheMatrix <- function(x = matrix()) { ## Returns the inverse cacheMatrix object - cacheSolve <- function(x, ...) { ## Return a matrix that is the inverse of 'x' invFunc <- x$getInverse()