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
31 lines (26 loc) · 840 Bytes
/
Copy pathcachematrix.R
File metadata and controls
31 lines (26 loc) · 840 Bytes
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
## As per the assignment the functions create and solve a matrix that allows
## for a cached solution
## Creates a list of functions to allow the caching to work
makeCacheMatrix <- function(x = matrix()) {
matrixinverse <- NULL
set <- function(y) {
x <<- y
matrixinverse <<- NULL
}
get <- function() x
setInverse <- function(inverse) matrixinverse <<- inverse
getInverse <- function() matrixinverse
list(set = set, get = get, setInverse = setInverse, getInverse = getInverse)
}
## Uses the list from makeCacheMatrix to solve or retrieve a Matrix
cacheSolve <- function(x, ...) {
matrixinverse <- x$getInverse()
if(!is.null(matrixinverse)) {
message("getting cached data")
return(matrixinverse)
}
data <- x$get()
matrixinverse <- solve(data, ...)
x$setInverse(matrixinverse)
matrixinverse
}