Skip to content

Commit 07a2203

Browse files
committed
First implementation
1 parent 7f657dd commit 07a2203

File tree

1 file changed

+22
-4
lines changed

1 file changed

+22
-4
lines changed

cachematrix.R

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,33 @@
11
## Put comments here that give an overall description of what your
22
## functions do
33

4-
## Write a short comment describing this function
4+
## Create a special matrix that can cache its inverse, modelled as list
5+
## of functions that perform the caching.
56

67
makeCacheMatrix <- function(x = matrix()) {
7-
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, setinverse = setinverse, getinverse = getinverse)
817
}
918

1019

11-
## Write a short comment describing this function
20+
## Function that resolves the inverse of matrix x using a cached version
21+
## if available.
1222

1323
cacheSolve <- function(x, ...) {
14-
## Return a matrix that is the inverse of 'x'
24+
i <- x$getinverse()
25+
if(!is.null(i)) {
26+
message("getting the cached inverse")
27+
return(i)
28+
}
29+
data <- x$get()
30+
i <- resolve(data, ...)
31+
x$setinverse(i)
32+
i
1533
}

0 commit comments

Comments
 (0)