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