Skip to content

Commit cdb6f62

Browse files
committed
w/ comments
1 parent 8892fc6 commit cdb6f62

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

cachematrix.R

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
1-
## Put comments here that give an overall description of what your
2-
## functions do
1+
## The functions below create a special object that stores a matrix vector and
2+
## caches its inverse.
33

4-
## Write a short comment describing this function
4+
## This function creates a special "matrix", which is really a list containing
5+
## a function to
6+
## 1. set the value of the vector
7+
## 2. get the value of the vector
8+
## 3. set the value of the inverse
9+
## 4. get the value of the inverse
510

611
makeCacheMatrix <- function(x = matrix()) {
712
inv <- NULL
@@ -18,7 +23,11 @@ makeCacheMatrix <- function(x = matrix()) {
1823
}
1924

2025

21-
## Write a short comment describing this function
26+
## The following function calculates the inverse of the special "matrix" created
27+
## with the above function. However, it first checks to see if the inverse has
28+
## already been calculated. If so, it gets the inverse from the cache and skips
29+
## the computation. Otherwise, it calculates the inverse of the data and sets
30+
## the value of the inverse in the cache via the setinv function.
2231

2332
cacheSolve <- function(x, ...) {
2433
## Return a matrix that is the inverse of 'x'
@@ -29,6 +38,6 @@ cacheSolve <- function(x, ...) {
2938
}
3039
data <- x$get()
3140
inv <- solve(data, ...)
32-
x$setmean(inv)
41+
x$setinv(inv)
3342
m
34-
}
43+
}

0 commit comments

Comments
 (0)