File tree Expand file tree Collapse file tree 1 file changed +29
-6
lines changed Expand file tree Collapse file tree 1 file changed +29
-6
lines changed Original file line number Diff line number Diff line change 1
- # # Put comments here that give an overall description of what your
2
- # # functions do
1
+ # # System to cache matrix inverse calculations
2
+ # #
3
3
4
- # # Write a short comment describing this function
5
4
6
- makeCacheMatrix <- function ( x = matrix ()) {
5
+ # # This is a 'factory' function for a cached matrix inverse calculator
7
6
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 )
8
20
}
9
21
10
22
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
12
26
13
27
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
15
37
}
38
+
You can’t perform that action at this time.
0 commit comments