Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 93cc08e

Browse files
committed
Add basic working implementations
1 parent 7f657dd commit 93cc08e

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

cachematrix.R

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

66
makeCacheMatrix <- function(x = matrix()) {
7+
invmatrix <- NULL
8+
set <- function(y) {
9+
x <<- y
10+
m <<- NULL
11+
}
712

13+
get <- function() x
14+
15+
setinverse <- function(inv) invmatrix <<- inv
16+
getinverse <- function() invmatrix
17+
18+
list(set=set, get=get, setinverse=setinverse, getinverse=getinverse)
819
}
920

1021

1122
## Write a short comment describing this function
1223

1324
cacheSolve <- function(x, ...) {
1425
## Return a matrix that is the inverse of 'x'
26+
m <- x$getinverse()
27+
if(!is.null(m)) {
28+
message("getting cached data")
29+
return(m)
30+
}
31+
data <- x$get()
32+
m <- solve(data, ...)
33+
x$setinverse(m)
34+
m
1535
}

0 commit comments

Comments
 (0)