Skip to content

Commit b98be2c

Browse files
committed
Second commit: implemented cahceSolve
1 parent 48dabca commit b98be2c

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

cachematrix.R

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,20 @@ makeCacheMatrix <- function(x = matrix()) {
1919
getinv = getinv)
2020
}
2121

22-
22+
## This function computes the inverse of the special "matrix" returned by
23+
## makeCacheMatrix above. If the inverse has already been calculated
24+
## (and the matrix has not changed), then cacheSolve should retrieve the
25+
## inverse from the cache.
2326

2427
cacheSolve <- function(x, ...) {
2528
## Return a matrix that is the inverse of 'x'
26-
29+
m <- x$getinv()
30+
if(!is.null(m)) {
31+
message("getting cached data")
32+
return(m)
33+
}
34+
data <- x$get()
35+
m <- solve(data, ...)
36+
x$setinv(m)
37+
m
2738
}

0 commit comments

Comments
 (0)