Skip to content

Commit 5158329

Browse files
committed
matrix with inverse cache
1 parent 7f657dd commit 5158329

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

cachematrix.R

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
1-
## Put comments here that give an overall description of what your
2-
## functions do
3-
4-
## Write a short comment describing this function
5-
6-
makeCacheMatrix <- function(x = matrix()) {
7-
1+
makeCacheMatrix <- function(x = matrix()){
2+
inv <- NULL
3+
get <- function() x
4+
inverse <- function() inv
5+
set_inverse <- function(m) inv <<- m
6+
list(get=get, inverse=inverse, set_inverse=set_inverse)
87
}
98

10-
11-
## Write a short comment describing this function
12-
13-
cacheSolve <- function(x, ...) {
14-
## Return a matrix that is the inverse of 'x'
9+
cacheSolve <- function(x, ...){
10+
inv <- x$inverse()
11+
if(!is.null(inv)) return(inv)
12+
dat <- x$get()
13+
inv <- solve(dat, ...)
14+
x$set_inverse(inv)
15+
inv
1516
}

0 commit comments

Comments
 (0)