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
34 lines (32 loc) · 1013 Bytes
/
cachematrix.R
File metadata and controls
34 lines (32 loc) · 1013 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
## Below functions helps in computing and cacheing the matrix inverse
## as computing inverse of a matrix is costly affair
## This function take matrix as input and create a object of matrix
## also help in getting and setting the matrix
makeCacheMatrix <- function(x = matrix()) {
k <- NULL
set <- function(b) {
x <<- b
k <<- NULL
}
get <- function() x
setinverse <- function(inverse) k <<- inverse
getinverse <- function() k
list(set = set,
get = get,
setinverse = setinverse,
getinverse = getinverse)
}
## This function checks whether the computed inverse is available?
## if it is then return the same, if not then compute the inverse,
## store and then return the inverse matrix
cacheSolve <- function(x, ...) {
j <- x$getinverse()
if (!is.null(j)) {
message("retrieving cached data")
return(j)
}
data <- x$get()
j <- solve(data, ...)
x$setinverse(j)
j
}