File tree Expand file tree Collapse file tree 1 file changed +27
-3
lines changed Expand file tree Collapse file tree 1 file changed +27
-3
lines changed Original file line number Diff line number Diff line change 2
2
# # functions do
3
3
4
4
# # Write a short comment describing this function
5
-
5
+ # # makeCacheMatrix creates a matrix object which allows caching of its inverse
6
+ # # parameter/argument x is an invertible matrix, defaulting to an empty matrix if x is not defined
7
+ # # A list is returned with operations for matrix setting/getting, and inverse matrix setting/getting
6
8
makeCacheMatrix <- function (x = matrix ()) {
7
-
9
+
10
+ inv <- NULL
11
+ set <- function (y ) {
12
+ x <<- y
13
+ inv <<- NULL
14
+ }
15
+
16
+ get <- function () x
17
+ setinverse <- function (inverse ) inv <<- inverse
18
+ getinverse <- function () inv
19
+
20
+ list (set = set , get = get , setinverse = setinverse , getinverse = getinverse )
8
21
}
9
22
10
23
11
24
# # Write a short comment describing this function
12
-
25
+ # # cacheSolve returns the inverse of the matrix supplied to makeCacheMatrix
26
+ # # if the inverse has already been calculated, the cached version is used and returned without
27
+ # # having to calculated/add extra overhead. If it has not been calculated prior, it is calculated, and then cached for
28
+ # # future retrievals
13
29
cacheSolve <- function (x , ... ) {
14
30
# # Return a matrix that is the inverse of 'x'
31
+ inv <- x $ getinverse()
32
+ if (! is.null(inv )) {
33
+ return (inv )
34
+ }
35
+ data <- x $ get()
36
+ inv <- solve(data , ... )
37
+ x $ setinverse(inv )
38
+ return (inv )
15
39
}
You can’t perform that action at this time.
0 commit comments