File tree Expand file tree Collapse file tree 1 file changed +42
-1
lines changed Expand file tree Collapse file tree 1 file changed +42
-1
lines changed Original file line number Diff line number Diff line change 5
5
6
6
makeCacheMatrix <- function (x = matrix ()) {
7
7
8
+ inverse <- NULL
9
+ set <- function (y ) {
10
+ x <<- y
11
+ inverse <<- NULL
12
+ }
13
+
14
+ get <- function () {
15
+ x
16
+ }
17
+
18
+ setInverse <- function (passedInverse ) {
19
+ inverse <<- passedInverse
20
+ }
21
+
22
+ getInverse <- function () {
23
+ inverse
24
+ }
25
+
26
+ list (
27
+ set = set ,
28
+ get = get ,
29
+ setInverse = setInverse ,
30
+ getInverse = getInverse
31
+ )
8
32
}
9
33
10
34
11
35
# # Write a short comment describing this function
36
+ # this function will handle the cacheMatrix object, and either
37
+ # retrieve a cached inverse for the current matrix, or create
38
+ # a new inverse and store it
12
39
13
40
cacheSolve <- function (x , ... ) {
14
- # # Return a matrix that is the inverse of 'x'
41
+ # # Return a matrix that is the inverse of 'x'
42
+ inverse <- x $ getInverse()
43
+
44
+ # there's already a cached inverse
45
+ if (! is.null(inverse )) {
46
+ message(' getting cached data' )
47
+ return (inverse )
48
+ }
49
+
50
+ # if not, get the original value of x, invert it and store it
51
+ data <- x $ get()
52
+ inverse <- solve(data , ... )
53
+ x $ setInverse(inverse )
54
+ inverse
55
+
15
56
}
You can’t perform that action at this time.
0 commit comments