File tree Expand file tree Collapse file tree 1 file changed +25
-9
lines changed Expand file tree Collapse file tree 1 file changed +25
-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
1
+ # # This lets you to cache `solve` operation for your matrix
5
2
3
+ # # Accepts matrix, returns list of functions
6
4
makeCacheMatrix <- function (x = matrix ()) {
7
-
5
+ m <- NULL
6
+ set <- function (y ) {
7
+ x <<- y
8
+ m <<- NULL
9
+ }
10
+ get <- function () x
11
+ setmatrix <- function (matrix ) m <<- matrix
12
+ getmatrix <- function () m
13
+ list (set = set , get = get ,
14
+ setmatrix = setmatrix ,
15
+ getmatrix = getmatrix )
8
16
}
9
17
10
-
11
- # # Write a short comment describing this function
12
-
18
+ # # Accepts list of functions, and uses them to store result of `solve`
19
+ # # operation into cache or get it from the cache.
13
20
cacheSolve <- function (x , ... ) {
14
- # # Return a matrix that is the inverse of 'x'
21
+ m <- x $ getmatrix()
22
+ if (! is.null(m )) {
23
+ message(" getting cached data" )
24
+ return (m )
25
+ }
26
+ data <- x $ get()
27
+ m <- solve(data , ... )
28
+ x $ setmatrix(m )
29
+ m
15
30
}
31
+
You can’t perform that action at this time.
0 commit comments