File tree Expand file tree Collapse file tree 1 file changed +24
-9
lines changed Expand file tree Collapse file tree 1 file changed +24
-9
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
5
-
6
1
makeCacheMatrix <- function (x = matrix ()) {
7
-
2
+ inverse <- NULL
3
+ set <- function (y ) {
4
+ x <<- y
5
+ inverse <<- NULL
6
+ }
7
+ get <- function () x
8
+ setinverse <- function (inv ) inverse <<- inv
9
+ getinverse <- function () inverse
10
+ list (set = set , get = get ,
11
+ setinverse = setinverse ,
12
+ getinverse = getinverse )
8
13
}
9
14
10
15
11
- # # Write a short comment describing this function
12
-
13
16
cacheSolve <- function (x , ... ) {
14
- # # Return a matrix that is the inverse of 'x'
17
+ # # Return a matrix that is the inverse of 'x'
18
+ inverse <- x $ getinverse()
19
+ if (! is.null(inverse )) {
20
+ message(" getting cached inverse matrix" )
21
+ return (inverse )
22
+ }
23
+
24
+ data <- x $ get()
25
+ message(" computing inverse matrix" )
26
+ inverse <- solve(data , ... )
27
+ x $ setinverse(inverse )
28
+ inverse
15
29
}
30
+
You can’t perform that action at this time.
0 commit comments