File tree Expand file tree Collapse file tree 1 file changed +30
-6
lines changed Expand file tree Collapse file tree 1 file changed +30
-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+ # # The following functions creates a special object
2+ # # to be able to cache the inverse of a matrix
3+ # # so it doesn't have to be calculated repeatedly from
4+ # # w/in a program
35
4- # # Write a short comment describing this function
6+ # # returns a list of functions to get and set the matrix
7+ # # and get and set the cached matrix
58
69makeCacheMatrix <- function (x = matrix ()) {
7-
10+ c <- NULL
11+ set <- function (y ) {
12+ x <<- y
13+ c <<- NULL # # this resets the cache b/c the matrix has been changed
14+ }
15+ get <- function () x
16+ setcache <- function (solve ) c <<- solve
17+ getcache <- function () c
18+ list (set = set , get = get ,
19+ setcache = setcache ,
20+ getcache = getcache )
821}
922
1023
11- # # Write a short comment describing this function
24+ # # This function checks to see if the inverse matrix
25+ # # has already been calculated and if not, it calculates
26+ # # it and sets it so it doesn't have to be done again
1227
1328cacheSolve <- function (x , ... ) {
14- # # Return a matrix that is the inverse of 'x'
29+ # # Return a matrix that is the inverse of 'x'
30+ c <- x $ getcache()
31+ if (! is.null(c )) {
32+ message(" getting cached data" )
33+ return (c )
34+ }
35+ matrix <- x $ get()
36+ c <- solve(matrix , ... ) # calculate inverse
37+ x $ setcache(c )
38+ c
1539}
You can’t perform that action at this time.
0 commit comments