File tree Expand file tree Collapse file tree 1 file changed +29
-6
lines changed Expand file tree Collapse file tree 1 file changed +29
-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
1
+ # # This is a pair of functions for calculating, caching,
2
+ # # and retrieving the inverse of a square matrix.
3
3
4
- # # Write a short comment describing this function
4
+ # # makeCacheMatrix is a functional interface to the inverse
5
+ # # matrix cache, providing a means of retrieving and setting
6
+ # # inverse matrix values.
5
7
6
8
makeCacheMatrix <- function (x = matrix ()) {
7
-
9
+ m <- NULL
10
+ set <- function (y ) {
11
+ x <<- y
12
+ m <<- NULL
13
+ }
14
+ get <- function () x
15
+ setsolve <- function (solve ) m <<- solve
16
+ getsolve <- function () m
17
+ list (set = set , get = get ,
18
+ setsolve = setsolve ,
19
+ getsolve = getsolve )
8
20
}
9
21
10
22
11
- # # Write a short comment describing this function
23
+ # # cacheSolve takes a matrix and returns the inverse in one of
24
+ # # two ways: (1) retrieves it from the cache, or (2) computes
25
+ # # it and stores the result in the cache before returning it.
12
26
13
27
cacheSolve <- function (x , ... ) {
14
- # # Return a matrix that is the inverse of 'x'
28
+ # # Return a matrix that is the inverse of 'x'
29
+ m <- x $ getsolve()
30
+ if (! is.null(m )) {
31
+ message(" getting cached data" )
32
+ return (m )
33
+ }
34
+ data <- x $ get()
35
+ m <- solve(data , ... )
36
+ x $ setsolve(m )
37
+ m
15
38
}
You can’t perform that action at this time.
0 commit comments