Skip to content

Commit dda193a

Browse files
committed
adding comments
1 parent d15a02a commit dda193a

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

cachematrix.R

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
1-
## Put comments here that give an overall description of what your
2-
## functions do
1+
## These functions work as a pair to manage the storage of the
2+
## inverse of a matrix and avoid re-calculating it if that's
3+
## avoidable.
34

4-
## Write a short comment describing this function
5+
6+
## Can be used to create a wrapper object around a matrix with
7+
## the primary purpose being to hold the matrix and the inverse
8+
## of that matrix if the cacheSolve matrix has been used to
9+
## calculate it. The wrapper object, a list, also contains
10+
## functions to get and set the matrix and inverse stored within.
511

612
makeCacheMatrix <- function(dataMatrix = matrix()) {
713
inv = NULL
@@ -17,17 +23,27 @@ makeCacheMatrix <- function(dataMatrix = matrix()) {
1723
}
1824

1925

20-
## Write a short comment describing this function
26+
## Used to retrieve or calculate the inverse of a matrix stored
27+
## within a wrapper list created by the makeCacheMatrix function.
2128

2229
cacheSolve <- function(matrixWrapper, ...) {
30+
31+
#Retrieve the inverse stored in the wrapper object
2332
inverse = matrixWrapper$getInverse()
33+
2434
if (!is.null(inverse)) {
35+
#Return the pre-calculated inverse
2536
message("getting cached data")
2637
return(inverse)
2738
}
39+
40+
# No inverse was found, so calculate it
2841
message("calculating data")
2942
dataMatrix = matrixWrapper$get()
3043
inverse = solve(dataMatrix)
44+
45+
# Store the caluclated inverse for future use
3146
matrixWrapper$setInverse(inverse)
47+
3248
inverse
3349
}

0 commit comments

Comments
 (0)