Skip to content

Commit 8759e91

Browse files
committed
add some comments
1 parent 13198a6 commit 8759e91

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

cachematrix.R

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,38 @@
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+
## Builds a special Matrix that can cache the inverse of itself when
2+
## using the cacheSolve function
53

64
makeCacheMatrix <- function(x = matrix()) {
75
i <- NULL
6+
# set the matrix and clear the cached value
87
set <- function(y) {
98
x <<- y
109
i <<- NULL
1110
}
1211
get <- function() x
12+
# cache the inverse in i
1313
setInverse <- function(inverse) i <<- inverse
14+
# retieve cached value
1415
getInverse <- function() i
1516
list(set = set, get = get,
1617
setInverse = setInverse,
1718
getInverse = getInverse)
1819
}
1920

2021

21-
## Write a short comment describing this function
22+
## Using the makeCacheMatrix solve the matrix and cache it
23+
## so that multiple cacheSolve calls will not perform the expensive
24+
## solve operation.
2225

2326
cacheSolve <- function(x, ...) {
2427
## Return a matrix that is the inverse of 'x'
28+
29+
# check to see if it's cached
2530
i <- x$getInverse()
2631
if(!is.null(i)) {
2732
message("getting cached value")
2833
return(i)
2934
}
35+
# not cached, so solve and store the value in the cache
3036
data <- x$get()
3137
i <- solve(data, ...)
3238
x$setInverse(i)

0 commit comments

Comments
 (0)