From c908bafdd4d502a3f3604a9201992433fc24bc82 Mon Sep 17 00:00:00 2001 From: Zlu3Dev Date: Tue, 4 Apr 2017 14:47:40 -0400 Subject: [PATCH] cachematrix.R changes --- cachematrix.R | 38 +++++++++++++++++++++++++++++--------- 1 file changed, 29 insertions(+), 9 deletions(-) diff --git a/cachematrix.R b/cachematrix.R index a50be65aa44..64be817567e 100644 --- a/cachematrix.R +++ b/cachematrix.R @@ -3,13 +3,33 @@ ## Write a short comment describing this function -makeCacheMatrix <- function(x = matrix()) { - -} - - +makeCacheMatrix <- function(x = matrix()){ + m <- NULL + set <- function(y){ + x <<- y # <<- only for function use + m <<- NULL + } + get <- function()x #call the function + setinverse <- function(inverse) m <<-inverse + #set the inverse function + getinverse <- function() m + #get the inverse function + list(set = set, get = get, + setinverse = setinverse, + getinverse = getinverse) + #create a list to store the set,get method + } ## Write a short comment describing this function - -cacheSolve <- function(x, ...) { - ## Return a matrix that is the inverse of 'x' -} +cacheSolve <- function(x,...){ + ## Return a matrix that is the inverse of 'x' + m <- x$getinverse() # call the get function + if(!is.null(m)){ + # check the null value + message("getting cached data") + return(m) + } + data<- x$get() + m <- solve(data,...) + x$setinverse(m) + m + } \ No newline at end of file