File tree Expand file tree Collapse file tree 1 file changed +21
-9
lines changed Expand file tree Collapse file tree 1 file changed +21
-9
lines changed Original file line number Diff line number Diff line change 1
- # # Put comments here that give an overall description of what your
2
- # # functions do
3
-
4
- # # Write a short comment describing this function
5
-
1
+ # # This function creates a special "matrix" object that can cache
2
+ # # its inverse.
6
3
makeCacheMatrix <- function (x = matrix ()) {
7
-
4
+ inverse <- NULL
5
+ get <- function () x
6
+ get_inverse <- function () inverse
7
+ set_inverse <- function (inv ) {
8
+ inverse <<- inv
9
+ }
10
+ list (get = get , get_inverse = get_inverse , set_inverse = set_inverse )
8
11
}
9
12
10
13
11
- # # Write a short comment describing this function
12
-
14
+ # # This function computes the inverse of the special "matrix" returned
15
+ # # by makeCacheMatrix above.
16
+ # #
17
+ # # If the inverse has already been calculated (and the matrix has not
18
+ # # changed), then the cachesolve should retrieve the inverse from the
19
+ # # cache.
13
20
cacheSolve <- function (x , ... ) {
14
- # # Return a matrix that is the inverse of 'x'
21
+ inv <- x $ get_inverse()
22
+ if (is.null(inv )) {
23
+ inv <- solve(x $ get(), ... )
24
+ x $ set_inverse(inv )
25
+ }
26
+ inv
15
27
}
You can’t perform that action at this time.
0 commit comments