Skip to content

Commit 7e3a79d

Browse files
author
Dale Johnson
committed
update for assignment
1 parent 7f657dd commit 7e3a79d

File tree

1 file changed

+29
-6
lines changed

1 file changed

+29
-6
lines changed

cachematrix.R

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,38 @@
1-
## Put comments here that give an overall description of what your
2-
## functions do
1+
## System to cache matrix inverse calculations
2+
##
33

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

6-
makeCacheMatrix <- function(x = matrix()) {
5+
## This is a 'factory' function for a cached matrix inverse calculator
76

7+
makeCacheMatrix <- function(x = matrix()) {
8+
inv <- NULL
9+
set <- function(y) {
10+
x <<- y
11+
inv <<- NULL
12+
}
13+
get <- function() x
14+
setinv <- function(inv_in) inv <<- inv_in
15+
getinv <- function() inv
16+
list(set = set,
17+
get = get,
18+
setinv = setinv,
19+
getinv = getinv)
820
}
921

1022

11-
## Write a short comment describing this function
23+
## This is the evaluation method for the cached matrix inverse calculator
24+
## It will used cached values when available, otherwise re-cache and return
25+
## newly calculated values
1226

1327
cacheSolve <- function(x, ...) {
14-
## Return a matrix that is the inverse of 'x'
28+
inv <- x$getinv()
29+
if(!is.null(inv)) {
30+
message("getting cached data")
31+
return(inv)
32+
}
33+
data <- x$get()
34+
inv <- solve(data, ...)
35+
x$setinv(inv)
36+
inv
1537
}
38+

0 commit comments

Comments
 (0)