File tree Expand file tree Collapse file tree 1 file changed +22
-1
lines changed Expand file tree Collapse file tree 1 file changed +22
-1
lines changed Original file line number Diff line number Diff line change 44# # Write a short comment describing this function
55
66makeCacheMatrix <- function (x = matrix ()) {
7-
7+ inv <- NULL
8+ set <- function (y ) {
9+ x <<- y
10+ inv <<- NULL
11+ }
12+ get <- function () x
13+ setInverse <- function (inverse ) inv <<- inverse
14+ getInverse <- function () inv
15+ list (set = set ,
16+ get = get ,
17+ setInverse = setInverse ,
18+ getInverse = getInverse )
819}
920
1021
1122# # Write a short comment describing this function
1223
1324cacheSolve <- function (x , ... ) {
1425 # # Return a matrix that is the inverse of 'x'
26+ # # Return a matrix that is the inverse of 'x'
27+ inv <- x $ getInverse()
28+ if (! is.null(inv )) {
29+ message(" getting cached data" )
30+ return (inv )
31+ }
32+ mat <- x $ get()
33+ inv <- solve(mat , ... )
34+ x $ setInverse(inv )
35+ inv
1536}
You can’t perform that action at this time.
0 commit comments