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

Skip to content

Commit a78a8e6

Browse files
committed
Submission.
1 parent 7f657dd commit a78a8e6

File tree

1 file changed

+27
-12
lines changed

1 file changed

+27
-12
lines changed

cachematrix.R

Lines changed: 27 additions & 12 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+
setinverse <- function(solve) m <<- solve
10+
getinverse <- function() m
11+
list(set = set, get = get,
12+
setinverse = setinverse,
13+
getinverse = getinverse)
814
}
9-
10-
11-
## Write a short comment describing this function
12-
15+
## This function computes the inverse of the special "matrix" returned by
16+
## makeCacheMatrix above. If the inverse has already been calculated (and
17+
## the matrix has not changed), then the cachesolve should retrieve the
18+
## inverse from the cache.
1319
cacheSolve <- function(x, ...) {
14-
## Return a matrix that is the inverse of 'x'
15-
}
20+
## Return a matrix that is the inverse of 'x'
21+
m <- x$getinverse()
22+
if(!is.null(m)) {
23+
message("getting cached data")
24+
return(m)
25+
}
26+
data <- x$get()
27+
m <- solve(data, ...)
28+
x$setinverse(m)
29+
m
30+
}

0 commit comments

Comments
 (0)