File tree Expand file tree Collapse file tree 1 file changed +22
-4
lines changed Expand file tree Collapse file tree 1 file changed +22
-4
lines changed Original file line number Diff line number Diff line change 1
1
# # Put comments here that give an overall description of what your
2
2
# # functions do
3
3
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.
5
6
6
7
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 )
8
17
}
9
18
10
19
11
- # # Write a short comment describing this function
20
+ # # Function that resolves the inverse of matrix x using a cached version
21
+ # # if available.
12
22
13
23
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
15
33
}
You can’t perform that action at this time.
0 commit comments