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