Skip to content

Commit 4facc0f

Browse files
committed
Added some comments explaining the code
1 parent 1eb4341 commit 4facc0f

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

cachematrix.R

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
1-
## Put comments here that give an overall description of what your
2-
## functions do
1+
## The makeCacheMatrix and cacheSolve functions work together to create a
2+
## special matrix wrapper object that can cache its own inverse value.
33

4-
## Write a short comment describing this function
4+
## The makeCacheMatrix function creates a special object that wraps a matrix
5+
## object and provides accessor functions to the matrix object and the cached
6+
## inverse of the matrix.
57

68
makeCacheMatrix <- function(x = matrix()) {
79
i <- NULL
810

911
set <- function(y) {
12+
# Clear the cached inverse whenever we update the matrix object to make
13+
# sure we don't return an incorrect inverse.
1014
message("clearing the cached inverse")
1115
i <<- NULL
1216
x <<- y
@@ -18,7 +22,9 @@ makeCacheMatrix <- function(x = matrix()) {
1822
}
1923

2024

21-
## Write a short comment describing this function
25+
## The cacheSolve function calculates the inverse of the given matrix and
26+
## caches it on that object. If the inverse of the give matrix is already
27+
## cached it returns instead of calculating it anew.
2228

2329
cacheSolve <- function(x, ...) {
2430
## Return a matrix that is the inverse of 'x'

0 commit comments

Comments
 (0)