10000 assignment solution · sdether/ProgrammingAssignment2@91808b6 · GitHub
[go: up one dir, main page]

Skip to content

Commit 91808b6

Browse files
committed
assignment solution
1 parent 7f657dd commit 91808b6

File tree

1 file changed

+28
-6
lines changed

1 file changed

+28
-6
lines changed

cachematrix.R

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,37 @@
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
33

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
57

68
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)
820
}
921

1022

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
1226

1327
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
1537
}

0 commit comments

Comments
 (0)
0