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