File tree Expand file tree Collapse file tree 1 file changed +28
-4
lines changed Expand file tree Collapse file tree 1 file changed +28
-4
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 allow a user to cache the inverse computation on
2+ # # a matrix. This is beneficial in that the inverse will not need to be
3+ # # recomputed for each iteration of a loop.
34
4- # # Write a short comment describing this function
5+ # # In this function we create 4 methods that allow the user to get
6+ # # and set a cached matrix, as well get and set the value for the inverse
7+ # # of the matrix.
8+ # # makeCacheMatrix returns a list of these 4 functions so that a user
9+ # # can appropriately update the cached inverse.
510
611makeCacheMatrix <- function (x = matrix ()) {
12+ i <- NULL
13+ set <- function (y ) {
14+ x <<- y
15+ i <<- NULL
16+ }
17+ get <- function () x
18+ setinverse <- function (inverse ) i <<- inverse
19+ getinverse <- function () i
20+ list (set = set , get = get ,
21+ setmean = setmean ,
22+ getmean = getmean )
723
824}
925
1026
1127# # Write a short comment describing this function
1228
1329cacheSolve <- function (x , ... ) {
14- # # Return a matrix that is the inverse of 'x'
30+ i <- x $ getinverse()
31+ if (! is.null(i )) {
32+ message(" getting cached inverse" )
33+ return (i )
34+ }
35+ data <- x $ get()
36+ i <- solve(data , ... )
37+ x $ setinverse(i )
38+ i
1539}
You can’t perform that action at this time.
0 commit comments