File tree Expand file tree Collapse file tree 1 file changed +24
-8
lines changed Expand file tree Collapse file tree 1 file changed +24
-8
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
3
-
4
- # # Write a short comment describing this function
5
1
6
2
makeCacheMatrix <- function (x = matrix ()) {
7
-
3
+ # # matrix wrapper
4
+ # # x the original matrix
5
+ # # inv inverse matrix
6
+ inv <- NULL
7
+ set <- function (y ) {
8
+ x <<- y
9
+ inv <<- NULL
10
+ }
11
+ get <- function () x
12
+ setinverse <- function (solve ) inv <<- solve
13
+ getinverse <- function () inv
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
12
-
13
20
cacheSolve <- function (x , ... ) {
14
- # # Return a matrix that is the inverse of 'x'
21
+ # # Return a matrix that is the inverse of 'x'
22
+ inv <- x $ getinverse
23
+ if (! is.null(inv )) {
24
+ message(" getting cached data" )
25
+ return (inv )
26
+ }
27
+ data <- x $ get()
28
+ inv <- solve(data , ... )
29
+ x $ setinverse(inv )
30
+ inv
15
31
}
You can’t perform that action at this time.
0 commit comments