File tree Expand file tree Collapse file tree 1 file changed +5
-4
lines changed Expand file tree Collapse file tree 1 file changed +5
-4
lines changed Original file line number Diff line number Diff line change 10
10
11
11
# makeCacheMatrix creates a new list object that has the following methods:
12
12
# a getter, a setter, inverse calculator/setter, inverse retriever/getter.
13
+ # This list object is a wrapper around the input matrix
13
14
14
15
makeCacheMatrix <- function (x = matrix ()) {
15
16
m <- NULL
16
17
set <- function (y ) {
17
- x <<- y
18
- m <<- NULL
18
+ x <<- y # store the input matrix
19
+ m <<- NULL # placeholder for inverse matrix, to be filled with the setter
19
20
}
20
21
get <- function () x
21
22
setinverse <- function (solve ) m <<- solve
@@ -37,9 +38,9 @@ cacheSolve <- function(x, ...) {
37
38
return (m )
38
39
}
39
40
message(" Don't have computation cached. Calculating inverse of input matrix..." )
40
- data <- x $ get()
41
+ data <- x $ get() # pull out the actual input matrix from the input (list object)
41
42
m <- solve(data ) # calculate the inverse of the given matrix
42
- x $ setinverse(m )
43
+ x $ setinverse(m ) # store the inverse in the cache
43
44
m
44
45
}
45
46
You can’t perform that action at this time.
0 commit comments