diff --git a/cachematrix.R b/cachematrix.R index a50be65aa44..f25c8415ea3 100644 --- a/cachematrix.R +++ b/cachematrix.R @@ -1,15 +1,29 @@ -## 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 - +#making Cache Matrix cacheSolve <- function(x, ...) { ## Return a matrix that is the inverse of 'x' } +makeCacheMatrix <- function(x = matrix(sample(1:100,9),3,3)) { + s <- NULL + set <- function(y) { + x <<- y + s <<- NULL + } + get <- function() x + setsolve <- function(solve) s <<- solve + getsolve <- function() s + list(set = set, get = get, + setsolve = setsolve, + getsolve = getsolve) +} +#solving cache +CacheSolve <- function(x, ...) { + s <- x$getsolve() + if(!is.null(s)) { + message("getting inversed matrix") + return(s) + } + data <- x$get() + s <- solve(data, ...) + x$setsolve(s) + s +}