forked from rdpeng/ProgrammingAssignment2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcachematrix.R
56 lines (43 loc) · 997 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
45
46
47
48
49
50
51
52
53
54
55
56
## Put comments here that give an overall description of what your
## functions do
## Creates a matrix and cache its inverse
makeCacheMatrix <- function(x = matrix()) {
#cached inverse
inv <- NULL
#set the matrix
set <- function(y)
{
x <<- y
inv <<- NULL
}
#get the data matrix
get <- function()
{
x
}
#set the inverse
setinv <- function(computedinv)
{
inv<<- computedinv
}
#get the inverse
getinv <- function()
{
inv
}
#return a list with pointer to funcion
list(set=set, get=get, setinv=setinv, getinv=getinv)
}
## Return a matrix that is the inverse of 'x'
cacheSolve <- function(x, ...) {
cacheHit <- x$getinv()
if (!is.null(cacheHit))
{
message("hit from cache")
return (cacheHit)
}
data <- x$get();
inv <- solve(data)
x$setinv(inv)
inv
}