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