Skip to content

Commit 6ad1281

Browse files
authored
Update cachematrix.R
1 parent 7f657dd commit 6ad1281

File tree

1 file changed

+17
-8
lines changed

1 file changed

+17
-8
lines changed

cachematrix.R

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,22 @@
33

44
## Write a short comment describing this function
55

6-
makeCacheMatrix <- function(x = matrix()) {
7-
6+
makeCacheMatrix <- function() {
7+
mat <- NULL
8+
inv_cache <- NULL
9+
setMatrix <-function(x){
10+
mat <<-x
11+
inv_cache<<- NULL
812
}
9-
10-
11-
## Write a short comment describing this function
12-
13-
cacheSolve <- function(x, ...) {
14-
## Return a matrix that is the inverse of 'x'
13+
getInverse <- function() {
14+
if (is.null(inv_cache)){
15+
inv_cache <<-solve(mat)
16+
}
17+
inv_cache
18+
}
19+
list(setMatrix=setMatrix,getInverse = getInverse)
20+
}
21+
cacheSolve <- function(x,...){
22+
inv_cache <-x$getInverse()
23+
inv_cache
1524
}

0 commit comments

Comments
 (0)