File tree Expand file tree Collapse file tree 1 file changed +26
-5
lines changed Expand file tree Collapse file tree 1 file changed +26
-5
lines changed Original file line number Diff line number Diff line change 1
- # # Put comments here that give an overall description of what your
2
- # # functions do
1
+ # # Cache the inverse of a matrix.
3
2
4
- # # Write a short comment describing this function
3
+ # # Create a special matrix which can store its inverse.
5
4
6
5
makeCacheMatrix <- function (x = matrix ()) {
7
-
6
+ m <- NULL
7
+ set <- function (y ){
8
+ x <<- y
9
+ m <<- NULL
10
+ }
11
+ get <- function () x
12
+ setInverse <- function (solve ) m <<- solve
13
+ getInverse <- function () m
14
+ list (set = set , get = get ,
15
+ setInverse = setInverse ,
16
+ getInverse = getInverse )
8
17
}
9
18
10
19
11
- # # Write a short comment describing this function
20
+ # # Before compute the inverse of matrix x, see if x has it cached , and return that if do.
12
21
13
22
cacheSolve <- function (x , ... ) {
14
23
# # Return a matrix that is the inverse of 'x'
24
+ m <- x $ getInverse()
25
+ if (! is.null(m )) {
26
+ message(" getting cached data" )
27
+ return (m )
28
+ }
29
+ data <- x $ get()
30
+ m <- solve(data )
31
+ x $ setInverse(m )
32
+ m
15
33
}
34
+
35
+
36
+
You can’t perform that action at this time.
0 commit comments