Skip to content

Commit 8a6ed2e

Browse files
committed
Final version, tested. -v2
1 parent 2bcf8c5 commit 8a6ed2e

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

cachematrix.R

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,13 @@
1010

1111
# makeCacheMatrix creates a new list object that has the following methods:
1212
# a getter, a setter, inverse calculator/setter, inverse retriever/getter.
13+
# This list object is a wrapper around the input matrix
1314

1415
makeCacheMatrix <- function(x = matrix()) {
1516
m <- NULL
1617
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
1920
}
2021
get <- function() x
2122
setinverse <- function(solve) m <<- solve
@@ -37,9 +38,9 @@ cacheSolve <- function(x, ...) {
3738
return(m)
3839
}
3940
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)
4142
m <- solve(data) # calculate the inverse of the given matrix
42-
x$setinverse(m)
43+
x$setinverse(m) # store the inverse in the cache
4344
m
4445
}
4546

0 commit comments

Comments
 (0)