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+ # # These two functions are used to effeciently and with caching
2+ # # facilitate the return of the inverse of a square matrix
3+ # # a list of set and get functions are used to accomplish this
34
4- # # Write a short comment describing this function
5+ # # makeCacheMatrix takes in a square matrix and sets up a list that gives
6+ # # access to set or get the matrix and its inverse
7+ # # this list is a special matrix
58
69makeCacheMatrix <- function (x = matrix ()) {
7-
10+ i <- NULL
11+ set <- function (y ) {
12+ x <<- y
13+ i <<- NULL
14+ }
15+ get <- function () x
16+ setinverse <- function (inverse ) i <<- inverse
17+ getinverse <- function () i
18+ list (set = set , get = get ,
19+ setinverse = setinverse ,
20+ getinverse = getinverse )
821}
922
1023
11- # # Write a short comment describing this function
24+ # # cacheSolve takes in a special matrix from makeCacheMatrix and using its
25+ # # functions sets the inverse and saves it to cache or gets it from cache
1226
1327cacheSolve <- 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 data" )
31+ return (i )
32+ }
33+ data <- x $ get()
34+ i <- solve(data , ... )
35+ x $ setinverse(i )
36+ i
1537}
You can’t perform that action at this time.
0 commit comments