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
40 lines (28 loc) · 851 Bytes
/
cachematrix.R
File metadata and controls
40 lines (28 loc) · 851 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
38
39
40
## 1. set the value of matrix
## 2. get the value of matrix
## 3. set the value of inverse
## 4. get the value of inverse
makeCacheMatrix <- function(x = matrix()) {
invmatrix = NULL
set = function(y) {
x <<- y
invmatrix <<- NULL
}
get = function() x
setinv = function(inverse) invmatrix <<- inverse
getinv = function() invmatrix
list(set=set, get=get, setinv=setinv, getinv=getinv)
}
## Function checks if Inverse of a matrix is already cached
## Calls the first function to find a cached value
## If not, then it computes
cacheSolve <- function(x, ...) {
invmatrix = x$getinv()
if (!is.null(invmatrix)){
return(invmatrix)
}
matrix.data = x$getinv()
invmatrix = solve(matrix.data, ...)
x$setinv(invmatrix)
return(invmatrix)
}