Skip to content

Commit a8c1716

Browse files
committed
finish
1 parent 7f657dd commit a8c1716

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+
## Caching the Inverse of a Matrix.
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()) {
6+
i <- NULL
7+
set <- function(y) {
8+
x <<- y
9+
i <<- NULL
10+
}
11+
get <- function() x
712

13+
setinverse <- function(inverse) i <<- inverse
14+
getinverse <- function() i
15+
list(set = set, get = get,
16+
setinverse = setinverse,
17+
getinverse = getinverse)
818
}
919

1020

11-
## Write a short comment describing this function
21+
## This function computes the inverse of the special "matrix" returned by makeCacheMatrix above.
1222

1323
cacheSolve <- function(x, ...) {
14-
## Return a matrix that is the inverse of 'x'
24+
i <- x$getinverse()
25+
if (!is.null(i)) {
26+
message("getting cached data")
27+
return(i)
28+
}
29+
data <- x$get()
30+
i <- solve(data, ...)
31+
x$setinverse(i)
32+
i
1533
}

0 commit comments

Comments
 (0)