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
37 lines (32 loc) · 954 Bytes
/
Copy pathcachematrix.R
File metadata and controls
37 lines (32 loc) · 954 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
36
37
## THe function of this set of functions is to calculate
## the inverse of a matrix
## The following makeCacheMatrix function set the matrix,
## get the matrix, set the inverse of matrix,
## get the inverse of matrix
makeCacheMatrix <- function(x = matrix()) {
Inv <- NULL
set <- function(y){
x <<- y
Inv <<- NULL
}
get <- function() x
setInv <- function(i) Inv <<- i
getInv <- function() Inv
list(set = set, get = get,
setInv = setInv,
getInv = getInv)
}
## The cacheSolve function calculate the inverse of the matrix that
## created in above function. It checks if the inverse has been calculated.
## If so, gets the result. Otherwise, calculate it.
cacheSolve <- function(x, ...) {
Inv <- x$getInv()
if(!is.null(Inv)){
message("Inverse has been calculated")
return(Inv)
}
InvCalc <- x$get()
Inv <- solve(InvCalc, ...)
x$setInv(Inv)
Inv
}