From ea01e8b3205f0bdf7d3eb2959e0e78e85fb6558a Mon Sep 17 00:00:00 2001 From: winfeel Date: Sun, 23 Oct 2016 16:04:59 +0800 Subject: [PATCH 1/2] Delete cachematrix.R --- cachematrix.R | 15 --------------- 1 file changed, 15 deletions(-) delete mode 100644 cachematrix.R diff --git a/cachematrix.R b/cachematrix.R deleted file mode 100644 index a50be65..0000000 --- a/cachematrix.R +++ /dev/null @@ -1,15 +0,0 @@ -## Put comments here that give an overall description of what your -## functions do - -## Write a short comment describing this function - -makeCacheMatrix <- function(x = matrix()) { - -} - - -## Write a short comment describing this function - -cacheSolve <- function(x, ...) { - ## Return a matrix that is the inverse of 'x' -} From 4cc330f27d109d22b6af4325955ee65e2621602d Mon Sep 17 00:00:00 2001 From: winfeel Date: Sun, 23 Oct 2016 16:29:29 +0800 Subject: [PATCH 2/2] Add files via upload My code for Programming assignment 2 --- cachematrix.R | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 cachematrix.R diff --git a/cachematrix.R b/cachematrix.R new file mode 100644 index 0000000..bf4a1f3 --- /dev/null +++ b/cachematrix.R @@ -0,0 +1,28 @@ +makeCacheMatrix <- function(x = matrix()) { + inv <- NULL + set <- function(y) { + x <<- y + inv <<- NULL + } + get <- function() x + setInverse <- function(inverse) inv <<- inverse + getInverse <- function() inv + list(set = set, + get = get, + setInverse = setInverse, + getInverse = getInverse) +} + + + +cacheSolve <- function(x, ...) { + inv <- x$getInverse() + if (!is.null(inv)) { + message("getting cached data") + return(inv) + } + mat <- x$get() + inv <- solve(mat, ...) + x$setInverse(inv) + inv +} \ No newline at end of file