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
39 lines (35 loc) · 951 Bytes
/
cachematrix.R
File metadata and controls
39 lines (35 loc) · 951 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
## makeCacheMatrix, cacheSolve --- functions which creates
## cached version of matrix in which inverse value of matrix is
## stored in "cache" in order to speed up computations
## makeCacheMatrix creates cached vesrion of
## input matrix. Cached version of a matrix stores matrix and
## also inverse of the matrix if it was computed previously
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 outputs inverse of cached version of
## matrix and stores this value if it was computed first time
cacheSolve <- function(x, ...) {
inverse<-x$getinv()
if(!is.null(inverse))
{
message("getting cached inverse")
return(inverse)
}
data<-x$get()
ans<-solve(data,...)
x$setinv(ans)
ans
}