forked from rdpeng/ProgrammingAssignment2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcachematrix.R
44 lines (35 loc) · 975 Bytes
/
cachematrix.R
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
## Implementation of a matrix which can cache its own Inverse
## creats a list of four functions to handle a matrix and its cache inverse
makeCacheMatrix <- function(x = matrix()) {
inverseMatrix <- NULL
set<-function (y){
x<<-y
inverseMatrix<<-NULL;
}
get<-function (y){
x
}
setInverseMatrix <- function (inverse){
inverseMatrix<<-inverse
}
getInverseMatrix <- function (){
inverseMatrix
}
list(set=set,
get=get,
setInverseMatrix=setInverseMatrix,
getInverseMatrix=getInverseMatrix)
}
## solve matrix created by makeCacheMatrix function to get the inversive
## using cache.
cacheSolve <- function(x, ...) {
## Return a matrix that is the inverse of 'x'
inverse <- x$getInverseMatrix()
if(! is.null(inverse)){
inverse
}else{
inverse <- solve(x$get())
x$setInverseMatrix(inverse)
inverse
}
}