File tree Expand file tree Collapse file tree 1 file changed +24
-7
lines changed
Expand file tree Collapse file tree 1 file changed +24
-7
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
3-
4- # # Write a short comment describing this function
51
2+ # # Return a matrix container object that can cache its inverse.
3+ # # Use with a caching function.
64makeCacheMatrix <- function (x = matrix ()) {
7-
5+ i <- NULL
6+ set <- function (y ) {
7+ x <<- y
8+ i <<- NULL
9+ }
10+ get <- function () x
11+ setinverse <- function (inverse ) i <<- inverse
12+ getinverse <- function () i
13+ list (set = set , get = get ,
14+ setinverse = setinverse ,
15+ getinverse = getinverse )
816}
917
1018
11- # # Write a short comment describing this function
1219
20+ # # Return a matrix inverse from a matrix container.
21+ # # Function caches the inverse in the container.
1322cacheSolve <- function (x , ... ) {
14- # # Return a matrix that is the inverse of 'x'
23+ i <- x $ getinverse()
24+ if (! is.null(i )) {
25+ message(" getting cached inverse" )
26+ return (i )
27+ }
28+ data <- x $ get()
29+ i <- solve(data )
30+ x $ setinverse(i )
31+ i
1532}
You can’t perform that action at this time.
0 commit comments