Skip to content

Commit 363318f

Browse files
committed
implemented task
1 parent 7f657dd commit 363318f

File tree

1 file changed

+25
-9
lines changed

1 file changed

+25
-9
lines changed

cachematrix.R

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,31 @@
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 lets you to cache `solve` operation for your matrix
52

3+
## Accepts matrix, returns list of functions
64
makeCacheMatrix <- function(x = matrix()) {
7-
5+
m <- NULL
6+
set <- function(y) {
7+
x <<- y
8+
m <<- NULL
9+
}
10+
get <- function() x
11+
setmatrix <- function(matrix) m <<- matrix
12+
getmatrix <- function() m
13+
list(set = set, get = get,
14+
setmatrix = setmatrix,
15+
getmatrix = getmatrix)
816
}
917

10-
11-
## Write a short comment describing this function
12-
18+
## Accepts list of functions, and uses them to store result of `solve`
19+
## operation into cache or get it from the cache.
1320
cacheSolve <- function(x, ...) {
14-
## Return a matrix that is the inverse of 'x'
21+
m <- x$getmatrix()
22+
if(!is.null(m)) {
23+
message("getting cached data")
24+
return(m)
25+
}
26+
data <- x$get()
27+
m <- solve(data, ...)
28+
x$setmatrix(m)
29+
m
1530
}
31+

0 commit comments

Comments
 (0)