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
42 lines (30 loc) · 1.09 KB
/
cachematrix.R
File metadata and controls
42 lines (30 loc) · 1.09 KB
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
## This functions are used to cache inverse of matrix, so if we have to calculate inverse of
## the same matrix repeatedly then this functions are helpful
## This function takes a matrix as argument and returns a list. This function caches the
## matrix provided and also stores its inverse.
makeCacheMatrix <- function(x = matrix()) {
inv <- NULL
set <- function(y){
x <<- y
inv <<- NULL
}
get <- function() x
setInverse <- function(inver) inv <<- inver
getInverse <- function() inv
list(set = set , get = get , setInverse = setInverse , getInverse = getInverse)
}
## This function returns inverse of matrix, if the inverse of the matrix has already been
## evaluated then it returns the cached inverse or else it solves for the inverse and caches
## the inverse for the matrix for further use.
cacheSolve <- function(x, ...) {
## Return a matrix that is the inverse of 'x'
inv <- x$getInverse()
if(!is.null(inv)){
message("Getting cached inverse")
return(inv)
}
data <- x$get()
inv <- solve(data , ...)
x$setInverse(inv)
return(inv)
}