We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 27dd396 commit c9112ceCopy full SHA for c9112ce
cachematrix.R
@@ -5,16 +5,13 @@
5
6
makeCacheMatrix <- function(x = matrix()) {
7
i <- NULL
8
-
9
set <- function(y) {
10
x <<- y
11
i <<- NULL
12
}
13
14
get <- function() x
15
16
- setinverse <- function(solve) i <<- solve
17
+ setinverse <- function(inverse) i <<- inverse
18
getinverse <- function() i
19
20
list(set = set, get = get,
@@ -27,4 +24,15 @@ makeCacheMatrix <- function(x = matrix()) {
27
24
28
25
cacheSolve <- function(x, ...) {
29
26
## Return a matrix that is the inverse of 'x'
+ i <- x$getinverse()
+
+ 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
38
0 commit comments