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