forked from rdpeng/ProgrammingAssignment2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcachematrix.R
37 lines (32 loc) · 988 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
36
37
## These functions allow for performing a matrix inversion, then caching the result
## for reuse later
## This function acts as the caching environment for inverted matrices, allowing for
## setting and getting the values stored within
makeCacheMatrix <- function(x = matrix()) {
mi <- NULL
set <- function(y) {
x <<- y
mi <<- NULL
}
get <- function() x
setMatrixInverse <- function(matrixInverse) mi <<- matrixInverse
getMatrixInverse <- function() mi
list(set = set, get = get,
setMatrixInverse = setMatrixInverse,
getMatrixInverse = getMatrixInverse)
}
## This function will return a cached inverted matrix if it exists or calculate
## it, cache it, then return it
cacheSolve <- function(x, ...) {
mi <- x$getMatrixInverse()
if (is.null(mi)) {
data <- x$get()
mi <- solve(data, ...)
x$setMatrixInverse(mi)
}
else
{
message("getting cached data")
}
mi
}