forked from rdpeng/ProgrammingAssignment2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcachematrix.R
43 lines (37 loc) · 1.17 KB
/
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
38
39
40
41
42
43
## Function that creates an "object" representation on a Matrix
## with cache features and helper "methods".
makeCacheMatrix <- function(theMatrix = matrix()) {
inverseMatrix <- NULL
# Definition of helper method for seting the matrix
set <- function(y) {
theMatrix <<- y
inverseMatrix <<- NULL
}
# Definition of helper method for getting the matrix
get <- function() {
theMatrix
}
# Definition of helper method for seting the inverse matrix
setInverse <- function(m){
inverseMatrix <<- m
}
# Definition of helper method for getting the inverse matrix
getInverse <- function() {
inverseMatrix
}
list(set = set, get = get, setInverse = setInverse, getInverse = getInverse)
}
## Function that takes a cacheable matrix created with makeCacheMatrix
## and returns the cached inverse matrix, if applicable
cacheSolve <- function(x, ...) {
## Return a matrix that is the inverse of 'x'
m <- x$getInverse()
if(!is.null(m)) {
message("getting cached data")
return(m)
}
data <- x$get()
m <- solve(data, ...)
x$setInverse(m)
m
}