forked from rdpeng/ProgrammingAssignment2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cachematrix.R
35 lines (32 loc) · 1.01 KB
/
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
# makeCacheMatrix takes a matrix, saved in the private variable x
# return value of the makeCacheMatrix function is a list
# of functions that we want to expose as public.
# these are accessed with the $ operator. Any variables
# declared inside makeVector but not exported as part of this list
# are private...they are inaccessible to any caller of this function
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)
}
# cacheSolve takes a caching matrix created with makeCacheMatrix and
# return the caching vector
cacheSolve <- function(x, ...) {
## Return a matrix that is the inverse of 'x'
m <- x$getInv()
if(!is.null(m)) {
message("Getting cached data")
return(m)
}
data <- x$get()
m <- solve(data, ...)
x$setInv(m)
m
}
## Abhi was here