Skip to content

Commit 11a9484

Browse files
committed
completed
1 parent 7f657dd commit 11a9484

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

cachematrix.R

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,32 @@
55

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

8+
i <- NULL
9+
set <- function (y) {
10+
x <<- y
11+
i <<- NULL
12+
}
13+
get <- function() x
14+
setinverse <- function(inverse) i <<- inverse
15+
getinverse <- function() i
16+
list(set = set, get = get,
17+
setinverse = setinverse,
18+
getinverse = getinverse)
819
}
920

1021

1122
## Write a short comment describing this function
1223

1324
cacheSolve <- function(x, ...) {
1425
## Return a matrix that is the inverse of 'x'
26+
27+
i <- x$getinverse()
28+
if(!is.null(i)) {
29+
message("getting cached data")
30+
return(i)
31+
}
32+
data <- x$get()
33+
i <- solve(data, ...)
34+
x$setinverse(i)
35+
i
1536
}

0 commit comments

Comments
 (0)