forked from rdpeng/ProgrammingAssignment2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cachematrix.R
34 lines (29 loc) · 953 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
## These functions work together to return the cached inverse of a matrix
## if it has already been calculated once.
##
## The function makeCacheMatrix helps set up a wrapper over the matrix object
## to store and retrieve data of a matrix and the inverse of the matrix
makeCacheMatrix <- function(x = matrix()) {
mInv <- NULL
setData <- function(y) {
x <<- y
mInv <<- NULL
}
getData <- function() x
setInv <- function(aInv) mInv <<- aInv
getInv <- function() mInv
list(setData = setData, getData = getData, setInv = setInv, getInv = getInv)
}
## This is the caller function which will actually be called by the
cacheSolve <- function(x, ...) {
mInv <- x$getInv()
if(!is.null(mInv)) {
message ("getting cached inverse")
return(mInv)
}
data <- x$getData()
mInv <- solve(data, ...)
x$setInv(mInv)
mInv
## Return a matrix that is the inverse of 'x'
}