diff --git a/emmalucas b/emmalucas new file mode 100644 index 00000000000..17bad9d144f --- /dev/null +++ b/emmalucas @@ -0,0 +1,38 @@ + +## Put comments here that give an overall description of what your +## functions do + +## This function creates a special "matrix" object +## that can cache its inverse. + +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) +} + +## This function computes the inverse of the special +## "matrix" returned by `makeCacheMatrix` above. If the inverse has +## already been calculated (and the matrix has not changed), then +## `cacheSolve` should retrieve the inverse from the cache. + + +cacheSolve <- function(x, ...) { + inv <- x$getinverse() + if(!is.null(inv)) { + message("getting cached data.") + return(inv) + } + data <- x$get() + inv <- solve(data) + x$setinverse(inv) + inv +}