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