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
26 lines (24 loc) · 808 Bytes
/
cachematrix.R
File metadata and controls
26 lines (24 loc) · 808 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
## makeCacheMatrix creates a CachedMatrix object with 4 methods:
## set : set the matrix to the given input x
## get : get the matrix
## setInverse : set the inverse of the matrix
## getInverse : get the inverse of the matrix, first checking cache
makeCacheMatrix <- function(sqrMatrix = matrix()) {
inverse <- NULL
set <- function(x) {
sqrMatrix <<- x
inverse <<- NULL
}
get <- function() sqrMatrix
setInverse <- function(inv) inverse <<- inv
getInverse <- function() {
if(is.null(inverse)){
message("Solving inverse...")
setInverse(solve(sqrMatrix))
}
inverse
}
list(set=set, get=get, setInverse=setInverse, getInverse=getInverse)
}
## cacheSolve returns the inverse of a given cacheMatrix
cacheSolve <- function(cacheMatrix, ...) cacheMatrix$getInverse()