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
43 lines (33 loc) · 1.16 KB
/
Copy pathcachematrix.R
File metadata and controls
43 lines (33 loc) · 1.16 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
43
## Here, I'm solving 2nd Programming assignment in the course "R PRogramming"
## I'm creating two functions 1. makeCacheMatrix and 2.cacheSolve
## Here, "makeCacheMatrix" function creates special "matrix"
##object that can cache its inverse. For e.g. matrix that we will
## pass through the function, will get stored & its inverse will
## be cached
makeCacheMatrix <- function(x = matrix()) {
inver <- NULL
set <- function(y){
x <<- y
inver <<- NULL
}
get <- function() x
setinver <- function(inverse) inver <<- inverse
getinver <- function() inver
list(set = set, get = get, setinver= setinver, getinver = getinver)
}
## cachesolve, takes the matrix as input. Then it checks whether
## inverse of the input matrix is already cached or not
## If inverse is already cached, then it'll retrive the inverse
## otherwise it'll calcualte the inverse and store it in cahce
cacheSolve <- function(x, ...) {
## Return a matrix that is the inverse of 'x'
inver <- x$getinver()
if (!is.null(inver)){
message("Cached data will be shown")
return(inver)
}
inp <- x$get()
inver <- solve(inp,...)
x$setinver(inver)
inver
}