forked from rdpeng/ProgrammingAssignment2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcachematrix.R
More file actions
36 lines (33 loc) · 1.05 KB
/
Copy pathcachematrix.R
File metadata and controls
36 lines (33 loc) · 1.05 KB
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
## These functions allow for potentially expensive matrix
## inverse calculations to be cached for improved performance
## on subsequent calls
## Creates a 'Cache Matrix' object by wrapping a matrix in a list
## containing functions used to get and set the matrix and it's inverse
makeCacheMatrix <- function(x = matrix()) {
inv <- NULL
get <- function() x
set <- function(y) {
inv <<- NULL
x <<- y
}
getInverse <- function() inv
setInverse <- function(inverse) inv <<- inverse
list(get = get, set = set,
getInverse = getInverse,
setInverse = setInverse)
}
## Solves the inverse of a Cache Matrix (see above).
## The result is stored in the Cache Matrix so that on subsequent
## calls with the same matrix, the cached result is returned instead
## of re-calculating the inverse
cacheSolve <- function(x, ...) {
inv <- x$getInverse()
if (!is.null(inv)) {
message("getting cached data")
return(inv)
}
data <- x$get()
inv <- solve(data, ...)
x$setInverse(inv)
inv
}