forked from rdpeng/ProgrammingAssignment2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cachematrix.R
31 lines (29 loc) · 798 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
## These functions will cache the inverse of a matrix.
## This function handles storing the matrix and its reverse after it is calculated.
makeCacheMatrix <- function (m = matrix)
{
inverseMatrix <- NULL
set <- function (y) {
inverseMatrix <<- NULL
}
get <- function () m
setInverse <- function(inverse) inverseMatrix <<- inverse
getInverse <- function() inverseMatrix
list (set = set, get = get, setInverse =setInverse, getInverse = getInverse)
}
## Gets data. This function uses
## If it exists, it gets the cached version, if not, it calculates it and stores it in cache.
cacheSolve <- function (x, ...)
{
m <- x$getInverse()
if (!is.null(m))
{
##Getting cached data
return(m)
}
##Calculate data
data <- x$get()
m <- solve(data)
x$setInverse(m)
m
}