File tree Expand file tree Collapse file tree 1 file changed +23
-19
lines changed Expand file tree Collapse file tree 1 file changed +23
-19
lines changed Original file line number Diff line number Diff line change 5
5
# # and retrieving a matrix (set, get), as well as storing and retrieving
6
6
# # the matrix's inverse (setinverse, getinverse).
7
7
makeCacheMatrix <- function (x = matrix ()) {
8
- inv <- NULL
9
- set <- function (y ) {
10
- x <<- y
11
- inv <<- NULL # # reset the inverse to null
12
- }
13
- get <- function () x
14
- setinverse <- function (inverse ) inv <<- inverse
15
- getinverse <- function () inv
16
- list (set = set , get = get ,
8
+ inv <- NULL
9
+
10
+ set <- function (y ) {
11
+ x <<- y
12
+ inv <<- NULL # # reset the inverse to null
13
+ }
14
+ get <- function () x
15
+
16
+ setinverse <- function (inverse ) inv <<- inverse
17
+ getinverse <- function () inv
18
+
19
+ list (set = set , get = get ,
17
20
setinverse = setinverse ,
18
21
getinverse = getinverse )
19
22
}
@@ -25,14 +28,15 @@ makeCacheMatrix <- function(x = matrix()) {
25
28
# # - If a cached value does not exist, then the function calculates
26
29
# # the inverse, caches it, and returns that value.
27
30
cacheSolve <- function (x , ... ) {
28
- # # Return a matrix that is the inverse of 'x'
29
- inv <- x $ getinverse()
30
- if (! is.null(inv )) {
31
- message(" getting cached data" )
32
- return (inv )
33
- }
34
- data <- x $ get()
35
- inv <- solve(data )
36
- x $ setinverse(inv )
37
- inv
31
+ inv <- x $ getinverse()
32
+ if (! is.null(inv )) {
33
+ message(" getting cached data" )
34
+ return (inv )
35
+ }
36
+
37
+ data <- x $ get()
38
+ inv <- solve(data )
39
+ x $ setinverse(inv )
40
+
41
+ inv
38
42
}
You can’t perform that action at this time.
0 commit comments