File tree Expand file tree Collapse file tree 1 file changed +28
-6
lines changed Expand file tree Collapse file tree 1 file changed +28
-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
+ # # This file contains two functions for creating a matrix container than can cache the inverse operation of said matrix
2
+ # # and a function to perform this inversion on that container
3
3
4
- # # Write a short comment describing this function
4
+ # # makeCacheMatrix optionally takes a matrix and constructs a container that
5
+ # # allows the setting and getting of the the contained matrix as well as the
6
+ # # inverse of that matrix
5
7
6
8
makeCacheMatrix <- function (x = matrix ()) {
7
-
9
+ i <- NULL
10
+ set <- function (y ) {
11
+ x <<- y
12
+ i <<- NULL
13
+ }
14
+ get <- function () x
15
+ setinverse <- function (inverse ) i <<- inverse
16
+ getinverse <- function () i
17
+ list (set = set , get = get ,
18
+ setinverse = setinverse ,
19
+ getinverse = getinverse )
8
20
}
9
21
10
22
11
- # # Write a short comment describing this function
23
+ # # cacheSolve requires a cacheable matrix container and will either return
24
+ # # the already contained cached version of the inverse of the contained
25
+ # # matrix or compute the inverse, cache it in the container and then return it
12
26
13
27
cacheSolve <- function (x , ... ) {
14
- # # Return a matrix that is the inverse of 'x'
28
+ i <- x $ getinverse()
29
+ if (! is.null(i )) {
30
+ message(" getting cached inverse matrix" )
31
+ return (i )
32
+ }
33
+ data <- x $ get()
34
+ i <- solve(data , ... )
35
+ x $ setinverse(i )
36
+ i
15
37
}
You can’t perform that action at this time.
0 commit comments