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
52 lines (34 loc) · 1.06 KB
/
cachematrix.R
File metadata and controls
52 lines (34 loc) · 1.06 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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
## Put comments here that give an overall description of what your
## functions do
## makeCacheMatrix creates a list with
# set -> set the value of the matrix
# get -> get the value of the matrix
# setInverse -> set the of inverse of the matrix
# getInverse -> get the of inverse of the matrix
makeCacheMatrix <- function(x = matrix()) {
invMat <- NULL
set <- function(y) {
x <<- y
invMat <<- NULL
}
get <- function() x
setInverse <- function(inverse) invMat <<- inverse
getInverse <- function() invMat
list(set=set, get=get, setInverse=setInverse, getInverse=getInverse)
}
## Return the inverse of a matrix. If the result is not cached, then it's computed.
cacheSolve <- function(x, ...) {
#get cache
invMat <- x$getInverse()
if(is.null(invMat)) {
#not cached - calculate inverse matrix
message('calculate inverse matrix')
invMat <- solve( x$get() )
x$setInverse(invMat)
}
return(invMat)
}
# m = makeCacheMatrix( rbind( c(1,1,0), c(1,0,1), c(0,1,0) ) )
# m$get()
# cacheSolve(m)
# cacheSolve(m)