diff --git a/cachematrix.R b/cachematrix.R index a50be65aa44..83414964b91 100644 --- a/cachematrix.R +++ b/cachematrix.R @@ -1,15 +1,35 @@ -## Put comments here that give an overall description of what your -## functions do - -## Write a short comment describing this function +## cachematrix.R +## +## Create a cache marix object in order +## to increase performance by not have +## to calculate repeatedly +## 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 }