Skip to content

Commit 759e909

Browse files
committed
Resolution
1 parent 7f657dd commit 759e909

File tree

1 file changed

+24
-9
lines changed

1 file changed

+24
-9
lines changed

cachematrix.R

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,30 @@
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-
1+
## This function creates a special "matrix" object that can cache its inverse.
62
makeCacheMatrix <- function(x = matrix()) {
7-
3+
m <- NULL
4+
set <- function(y) {
5+
x <<- y
6+
m <<- NULL
7+
}
8+
get <- function() x
9+
setmatrix <- function(solve) m <<- solve
10+
getmatrix <- function() m
11+
list(set = set, get = get,
12+
setmatrix = setmatrix,
13+
getmatrix = getmatrix)
14+
815
}
916

1017

11-
## Write a short comment describing this function
12-
18+
##This function computes the inverse of the special "matrix" returned by makeCacheMatrix above. If the inverse has already been calculated (and the matrix has not changed), then the cachesolve should retrieve the inverse from the cache.
1319
cacheSolve <- function(x, ...) {
14-
## Return a matrix that is the inverse of 'x'
20+
## Return a matrix that is the inverse of 'x'
21+
m <- x$getmatrix()
22+
if(!is.null(m)) {
23+
message("getting cached data")
24+
return(m)
25+
}
26+
matrix <- x$get()
27+
m <- solve(matrix, ...)
28+
x$setmatrix(m)
29+
m
1530
}

0 commit comments

Comments
 (0)