Skip to content

Commit

Permalink
Update cachematrix.R
Browse files Browse the repository at this point in the history
  • Loading branch information
agrawalreetika committed Jul 30, 2015
1 parent 7f657dd commit 3898d73
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion cachematrix.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,33 @@
## Write a short comment describing this function

makeCacheMatrix <- function(x = matrix()) {

m <- NULL
set <- function(y) {
x <<- y ## assign the input matrix y to the variable x in the
## parent environment
m <<- NULL ## re-initialize m in the parent environment to null
}
get <- function() x ## return the matrix x
setinverse <- function(inverse) m <<- inverse ## set the cache m equal
## to the inverse of the matrix x
getinverse <- function() m ## return the cached inverse of x
list(set = set, get = get,
setinverse = setinverse,
getinverse = getinverse)
}


## Write a short comment describing this function

cacheSolve <- function(x, ...) {
## Return a matrix that is the inverse of 'x'
m <- x$getinverse()
if(!is.null(m)) {
message("getting cached data")
return(m)
}
data <- x$get()
m <- solve(data, ...)
x$setinverse(m)
m
}

0 comments on commit 3898d73

Please sign in to comment.