diff --git a/cachematrix.R b/cachematrix.R index a50be65aa44..c974ba12bc4 100644 --- a/cachematrix.R +++ b/cachematrix.R @@ -1,15 +1,26 @@ ## Put comments here that give an overall description of what your -## functions do - -## Write a short comment describing this function - makeCacheMatrix <- function(x = matrix()) { - + m<-NULL + set<-function(y){ + x<<-y + m<<-NULL +} +get<-function() x +setmatrix<-function(solve) m<<- solve +getmatrix<-function() m +list(set=set, get=get, + setmatrix=setmatrix, + getmatrix=getmatrix) } - -## Write a short comment describing this function - -cacheSolve <- function(x, ...) { - ## Return a matrix that is the inverse of 'x' +cacheSolve <- function(x=matrix(), ...) { + m<-x$getmatrix() + if(!is.null(m)){ + message("getting cached data") + return(m) + } + matrix<-x$get() + m<-solve(matrix, ...) + x$setmatrix(m) + m }