Skip to content

Commit aa8e8d4

Browse files
committed
Completed the 2 functions needed for assignment
1 parent 7f657dd commit aa8e8d4

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

cachematrix.R

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,30 @@
33

44
## Write a short comment describing this function
55

6-
makeCacheMatrix <- function(x = matrix()) {
7-
6+
makeCacheMatrix <- function(X = matrix()) {
7+
M <- NULL
8+
set <- function(Y){
9+
X <<- Y
10+
M <<- NULL
11+
}
12+
get <- function() X
13+
setSolve <- function(solve) M <<- solve
14+
getSolve <- function() M
15+
list(set = set, get = get, setSolve = setSolve, getSolve=getSolve)
816
}
917

1018

1119
## Write a short comment describing this function
1220

13-
cacheSolve <- function(x, ...) {
21+
cacheSolve <- function(X, ...) {
1422
## Return a matrix that is the inverse of 'x'
23+
M <- X$getSolve()
24+
if(!is.null(M)){
25+
message("getting cached data")
26+
return (M)
27+
}
28+
data <- X$get()
29+
M <- solve(data, ...)
30+
X$setSolve(M)
31+
M
1532
}

0 commit comments

Comments
 (0)