File tree Expand file tree Collapse file tree 1 file changed +25
-4
lines changed Expand file tree Collapse file tree 1 file changed +25
-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
+ # # makeCacheMatrix creates a special matrix object that can cache its inverse
5
5
6
6
makeCacheMatrix <- function (x = matrix ()) {
7
-
7
+ i <- NULL
8
+ set <- function (y ) {
9
+ x <<- y
10
+ i <<- NULL
11
+ }
12
+ get <- function () x
13
+ setinverse <- function (inverse ) i <<- inverse
14
+ getinverse <- function () i
15
+ list (set = set , get = get ,
16
+ setinverse = setinverse ,
17
+ getinverse = getinverse )
8
18
}
9
19
10
-
11
- # # Write a short comment describing this function
20
+ # # cacheSolve computes the inverse of the special matrix object that is returned
21
+ # # by makeCacheMatrix. If the inverse has already been computed on this
22
+ # # particular matrix object, the inverse won't be recalculated; instead, it
23
+ # # is retrieved from the cache.
12
24
13
25
cacheSolve <- function (x , ... ) {
14
26
# # Return a matrix that is the inverse of 'x'
27
+ i <- x $ getinverse()
28
+ if (! is.null(i )) {
29
+ message(" getting cached data" )
30
+ return (i )
31
+ }
32
+ data <- x $ get()
33
+ i <- solve(data , ... )
34
+ x $ setinverse(i )
35
+ i
15
36
}
You can’t perform that action at this time.
0 commit comments