File tree Expand file tree Collapse file tree 1 file changed +22
-1
lines changed Expand file tree Collapse file tree 1 file changed +22
-1
lines changed Original file line number Diff line number Diff line change 4
4
# # This function creates a special "matrix" object that can cache its inverse.
5
5
6
6
makeCacheMatrix <- function (x = matrix ()) {
7
-
7
+ m <- NULL
8
+ set <- function (y ) {
9
+ x <<- y
10
+ m <<- NULL
11
+ }
12
+ get <- function () x
13
+ setinverse <- function (inverse ) m <<- inverse
14
+ getinverse <- function () m
15
+ list (set = set , get = get ,
16
+ setinverse = setinverse ,
17
+ getinverse = getinverse )
8
18
}
9
19
10
20
@@ -14,4 +24,15 @@ makeCacheMatrix <- function(x = matrix()) {
14
24
15
25
cacheSolve <- function (x , ... ) {
16
26
# # Return a matrix that is the inverse of 'x'
27
+ m <- x $ getinverse()
28
+ if (! is.null(m )) {
29
+ message(" getting cached data" )
30
+ return (m )
31
+ }
32
+ data <- x $ get()
33
+ m <- solve(data )
34
+ x $ setinverse(m )
35
+ m
17
36
}
37
+
38
+
You can’t perform that action at this time.
0 commit comments