forked from rdpeng/ProgrammingAssignment2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cachematrix.R
35 lines (31 loc) · 1003 Bytes
/
cachematrix.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
## Put comments here that give an overall description of what your
## functions do
## Write a short comment describing this function
## Function that can cache the inverse of a matrix
makeCacheMatrix <- function(x = matrix()) {
mat <- NULL
set <- function(y) {
x <<- y
mat <<- NULL
}
get <- function() x
setInvMat <- function(invMat) mat <<- invMat
getInvMat <- function() mat
list(set = set, get = get,
setInvMat = setInvMat,
getInvMat = getInvMat)
}
## Write a short comment describing this function
## function that computes the inverse of a matrix or return its cache if it exists
cacheSolve <- function(x, ...) {
## Return a matrix that is the inverse of 'x'
invMat <- x$getInvMat()
if(!is.null(invMat)) {
message("getting cached data")
return(invMat)
}
data <- x$get()
invMat <- solve(data, ...)
x$setInvMat(invMat)
invMat
}