Skip to content

Commit c9112ce

Browse files
committed
Added code for cacheSolve
1 parent 27dd396 commit c9112ce

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

cachematrix.R

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,13 @@
55

66
makeCacheMatrix <- function(x = matrix()) {
77
i <- NULL
8-
98
set <- function(y) {
109
x <<- y
1110
i <<- NULL
1211
}
1312

1413
get <- function() x
15-
16-
setinverse <- function(solve) i <<- solve
17-
14+
setinverse <- function(inverse) i <<- inverse
1815
getinverse <- function() i
1916

2017
list(set = set, get = get,
@@ -27,4 +24,15 @@ makeCacheMatrix <- function(x = matrix()) {
2724

2825
cacheSolve <- function(x, ...) {
2926
## Return a matrix that is the inverse of 'x'
27+
i <- x$getinverse()
28+
29+
if(!is.null(i)) {
30+
message("Getting cached data")
31+
return(i)
32+
}
33+
34+
data <- x$get()
35+
i <- solve(data, ...)
36+
x$setmean(i)
37+
i
3038
}

0 commit comments

Comments
 (0)