Skip to content

Commit 374a410

Browse files
committed
Add comments to cachematrix.R
1 parent 4296049 commit 374a410

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

cachematrix.R

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,17 @@
1-
## Put comments here that give an overall description of what your
2-
## functions do
1+
# The function `makeCacheMatrix` takes a matrix as an argument and returns a
2+
# special "matrix" object that caches the results of potentially time-consuming
3+
# computations applied to the matrix, for example the function `solve`
4+
# which returns the inverse of the matrix. You must use the companion function
5+
# `cacheSolve` instead of `solve` with this special "matrix" object to take
6+
# advantage of its time-saving caching behavior.
37

4-
## Write a short comment describing this function
58

9+
# This function creates a special "matrix" object that can cache its inverse.
10+
# This special "matrix" object is really a list containing four functions to:
11+
# 1. set the value of the matrix
12+
# 2. get the value of the matrix
13+
# 3. set the value of the inverse
14+
# 4. get the value of the inverse
615
makeCacheMatrix <- function(x = matrix()) {
716
inv <- NULL
817
set <- function(y) {
@@ -19,8 +28,10 @@ makeCacheMatrix <- function(x = matrix()) {
1928
}
2029

2130

22-
## Return a matrix that is the inverse of 'x'
23-
31+
# This function computes the inverse of the special "matrix" returned by
32+
# `makeCacheMatrix` above. If the inverse has already been calculated (and the
33+
# matrix has not changed), then `cacheSolve` should retrieve the inverse from
34+
# the cache.
2435
cacheSolve <- function(x, ...) {
2536
inv <- x$getinv()
2637
if(!is.null(inv)) {

0 commit comments

Comments
 (0)