Skip to content

Commit c5a55fd

Browse files
committed
finish two functions
1 parent 7f657dd commit c5a55fd

File tree

1 file changed

+23
-5
lines changed

1 file changed

+23
-5
lines changed

cachematrix.R

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,33 @@
1-
## Put comments here that give an overall description of what your
2-
## functions do
1+
## solve with cache
32

4-
## Write a short comment describing this function
3+
## This function creates a special "matrix" object that can cache its inverse.
54

65
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)
817
}
918

1019

11-
## Write a short comment describing this function
20+
## cache martix inverse function
1221

1322
cacheSolve <- function(x, ...) {
1423
## 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
1533
}

0 commit comments

Comments
 (0)