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

Skip to content

Commit 00589d7

Browse files
cathgoldcathgold
cathgold
authored and
cathgold
committed
cached matrix inverse
1 parent 7f657dd commit 00589d7

File tree

1 file changed

+33
-15
lines changed

1 file changed

+33
-15
lines changed

cachematrix.R

Lines changed: 33 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,33 @@
1-
## Put comments here that give an overall description of what your
2-
## functions do
3-
4-
## Write a short comment describing this function
5-
6-
makeCacheMatrix <- function(x = matrix()) {
7-
8-
}
9-
10-
11-
## Write a short comment describing this function
12-
13-
cacheSolve <- function(x, ...) {
14-
## Return a matrix that is the inverse of 'x'
15-
}
1+
## Put comments here that give an overall description of what your
2+
## functions do
3+
4+
## Write a short comment describing this function
5+
6+
makeCacheMatrix <- function(x = matrix()) {
7+
m <- NULL
8+
set <- function(y) {
9+
x <<- y
10+
m <<- NULL
11+
}
12+
get <- function() x
13+
setinverse <- function(inverse) m <<- inverse
14+
getinverse <- function() m
15+
list(set = set, get = get,
16+
setinverse = setinverse,
17+
getinverse = getinverse)
18+
}
19+
20+
21+
## Write a short comment describing this function
22+
23+
cacheSolve <- function(x, ...) {
24+
m <- x$getinverse()
25+
if(!is.null(m)) {
26+
message("getting cached data")
27+
return(m)
28+
}
29+
data <- x$get()
30+
m <- solve(data)
31+
x$setinverse(m)
32+
m
33+
}

0 commit comments

Comments
 (0)