diff --git a/cachematrix.R b/cachematrix.R index a50be65aa44..cd040b777d1 100644 --- a/cachematrix.R +++ b/cachematrix.R @@ -1,15 +1,34 @@ -## Put comments here that give an overall description of what your -## functions do +## This module contains utility functions to speed up calculations +## of the matrix inverse operation -## Write a short comment describing this function +## makeCacheMatrix returns a list containing helper functions +## to set and get its inverse makeCacheMatrix <- function(x = matrix()) { - + m <- NULL + set <- function(y) { + x <<- y + m <<- NULL + } + get <- function() x + setInverse <- function(inverse) m <<- inverse + getInverse <- function() m + list(set = set, get = get, + setInverse = setInverse, + getInverse = getInverse) } -## Write a short comment describing this function +## cacheSolve calculates or returns the cached result the inverse of a cacheMatrix cacheSolve <- function(x, ...) { - ## Return a matrix that is the inverse of 'x' + m <- x$getInverse() + if(!is.null(m)) { + message("getting cached data") + return(m) + } + data <- x$get() + m <- solve(data, ...) + x$setInverse(m) + m }