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