Skip to content

Commit c07769a

Browse files
committed
Assignment completed
1 parent 7f657dd commit c07769a

File tree

1 file changed

+25
-6
lines changed

1 file changed

+25
-6
lines changed

cachematrix.R

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,34 @@
1-
## Put comments here that give an overall description of what your
2-
## functions do
3-
4-
## Write a short comment describing this function
1+
## This function creates a special "matrix" object that can cache its inverse.
52

63
makeCacheMatrix <- function(x = matrix()) {
7-
4+
i <- NULL
5+
set <- function(y) {
6+
x <<- y
7+
i <<- NULL
8+
}
9+
get <- function() x
10+
setsolve <- function(solve) i <<- solve
11+
getsolve <- function() i
12+
list(set = set, get = get,
13+
setsolve = setsolve,
14+
getsolve = getsolve)
815
}
916

1017

11-
## Write a short comment describing this function
18+
## This function computes the inverse of the special "matrix" returned
19+
## by makeCacheMatrix above. If the inverse has already been calculated
20+
## (and the matrix has not changed), then cacheSolve should retrieve the
21+
## inverse from the cache.
1222

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

0 commit comments

Comments
 (0)