Skip to content

Commit 24ae052

Browse files
committed
finished
1 parent 7f657dd commit 24ae052

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

cachematrix.R

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

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

1020

11-
## Write a short comment describing this function
12-
1321
cacheSolve <- function(x, ...) {
14-
## Return a matrix that is the inverse of 'x'
22+
m <- x$getmatrix()
23+
if(!is.null(m)) {
24+
message("getting cached data")
25+
return(m)
26+
}
27+
data <- x$get()
28+
m <- solve(data)
29+
x$setmatrix(m)
30+
m
1531
}

0 commit comments

Comments
 (0)