Skip to content

Commit 83d246d

Browse files
Update cachematrix.R
1 parent 7f657dd commit 83d246d

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

cachematrix.R

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,30 @@
44
## Write a short comment describing this function
55

66
makeCacheMatrix <- function(x = matrix()) {
7-
7+
s <- NULL
8+
set <- function(y) {
9+
x <<- y
10+
s <<- NULL
11+
}
12+
get <- function() x
13+
setsolve <- function(solve) s <<- solve
14+
getsolve <- function() s
15+
list(set = set, get = get,
16+
setsolve = setsolve,
17+
getsolve = getsolve)
818
}
919

1020

1121
## Write a short comment describing this function
1222

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

0 commit comments

Comments
 (0)