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
38 lines (33 loc) · 1.08 KB
/
cachematrix.R
File metadata and controls
38 lines (33 loc) · 1.08 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
## Functions here are for caching inverse value of an invertible matrix
## which allows fast reuse of the stored value computed earlier
## instead of computing this value every time it is needed
## This function stores an input matrix, which inverted form is needed,
## and caches the inverse value of the specified matrix.
## Output of this function is an interface (a list of functions) which
## allows to get/set the matrix to be inverted and the inverted matrix
makeCacheMatrix <- function(x = matrix()) {
inv <- NULL
set <- function(y) {
x <<- y
inv <<- NULL
}
get <- function() x
setInv <- function(inverse) inv <<- inverse
getInv <- function() inv
list(set = set, get = get,
setInv = setInv,
getInv = getInv)
}
## This function gets the interface returned by the makeCacheMatrix
## and returns the inverse matrix
cacheSolve <- function(x, ...) {
inv <- x$getInv()
if(!is.null(inv)) {
message("getting cached data")
return(inv)
}
data <- x$get()
inv <- solve(data, ...)
x$setInv(inv)
inv
}