Skip to content

Commit 1dc05a5

Browse files
committed
Programm to cache an inverse of a matrix
1 parent e4eed41 commit 1dc05a5

1 file changed

Lines changed: 21 additions & 12 deletions

File tree

cachematrix.R

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,24 @@
1-
## Put comments here that give an overall description of what your
2-
## functions do
3-
4-
## Write a short comment describing this function
5-
61
makeCacheMatrix <- function(x = matrix()) {
7-
2+
m <- NULL
3+
set <- function(y) {
4+
x <<- y
5+
m <<- NULL
6+
}
7+
get <- function() x
8+
setsolve <- function(solve) m <<- solve
9+
getsolve <- function() m
10+
list(set = set, get = get,
11+
setsolve = setsolve,
12+
getsolve = getsolve)
813
}
9-
10-
11-
## Write a short comment describing this function
12-
1314
cacheSolve <- function(x, ...) {
14-
## Return a matrix that is the inverse of 'x'
15-
}
15+
m <- x$getsolve()
16+
if(!is.null(m)) {
17+
message("getting cached data")
18+
return(m)
19+
}
20+
data <- x$get()
21+
m <- solve(data, ...)
22+
x$setsolve(m)
23+
m
24+
}

0 commit comments

Comments
 (0)