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
35 lines (29 loc) · 927 Bytes
/
Copy pathcachematrix.R
File metadata and controls
35 lines (29 loc) · 927 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
32
33
34
35
## This combination of functions allows a matrix inverse to be stored
## in cache in a class that encompasses the matrix.
## Class that encompasses a matrix by adding a inverse function to it
makeCacheMatrix <- function(x = matrix()) {
inv <- NULL
set <- function(y) {
x <<- y
inv <<- NULL
}
get <- function() x
setSolve <- function(inverse) inv <<- inverse
getSolve <- function() inv
list(set = set, get = get, setSolve = setSolve, getSolve = getSolve)
}
## This function solves the encompassed matrix for an inverse.
## If the matrix has already had its inverse found, it will be just be very quick
cacheSolve <- function(x, ...) {
## Return a matrix that is the inverse of 'x'
inv <- x$getSolve()
if(is.null(inv)){
solution <- solve(x$get(),...)
x$setSolve(solution)
inv <- solution
} else{
print("Already solved, returning cached...")
return(inv)
}
inv
}