forked from rdpeng/ProgrammingAssignment2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cachematrix.R
36 lines (32 loc) · 825 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
## returns a special vector with the list of functions to
## get and set the vector values and also to store and retrieve the mean
makeCacheMatrix <- function(x = matrix()) {
inverse<-NULL
get<-function() x
set <- function(y) {
x <<- y
inverse <<- NULL
}
getInverse<-function(){
inverse
}
setInverse<-function(inv)
{
inverse<<- inv
}
list(set=set,get=get,getInverse=getInverse,setInverse=setInverse)
}
## Checks for the inverse of the matrix in cache
## if found in cache returns it or computes it and stores in cache via parent function
cacheSolve <- function(x, ...) {
inv<-x$getInverse()
if(!is.null(inv))
{
message("getting cached data")
return(inv)
}
matrix<-x$get()
inv<-solve(matrix)
x$setInverse(inv)
inv
}