File tree Expand file tree Collapse file tree 1 file changed +20
-3
lines changed Expand file tree Collapse file tree 1 file changed +20
-3
lines changed Original file line number Diff line number Diff line change 3
3
4
4
# # Write a short comment describing this function
5
5
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 )
8
16
}
9
17
10
18
11
19
# # Write a short comment describing this function
12
20
13
- cacheSolve <- function (x , ... ) {
21
+ cacheSolve <- function (X , ... ) {
14
22
# # 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
15
32
}
You can’t perform that action at this time.
0 commit comments