File tree Expand file tree Collapse file tree 1 file changed +32
-7
lines changed Expand file tree Collapse file tree 1 file changed +32
-7
lines changed Original file line number Diff line number Diff line change 1
- # # Put comments here that give an overall description of what your
2
- # # functions do
1
+ # # Cahce inverse of a matrix
2
+ # # 2 functions below make obect which store matrix
3
+ # # and calculate its inverse with caching.
3
4
4
- # # Write a short comment describing this function
5
+ # # makeCacheMatrix funtction creates "matrix"
6
+ # # object that can cache its inverse.
7
+ # #
5
8
6
9
makeCacheMatrix <- function (x = matrix ()) {
7
-
10
+ inver_m <- NULL
11
+ set <- function (y ){
12
+ x <<- y
13
+ inver_m <<- NULL
14
+ }
15
+ get <- function () x
16
+ setInvMat <- function (inverse ) inver_m <<- inverse
17
+ getInvMat <- function () inver_m
18
+ list (set = set , get = get ,
19
+ setInvMat = setInvMat ,
20
+ getInvMat = getInvMat )
8
21
}
9
22
10
-
11
- # # Write a short comment describing this function
23
+ # # Function cahceSolve computes inverse of special "matrix" from
24
+ # # makeCacheMatrix function indicated above.
25
+ # # If the inverse has already been calculated (and the matrix has not changed),
26
+ # # then the cachesolve should retrieve the inverse from the cache.
12
27
13
28
cacheSolve <- function (x , ... ) {
14
- # # Return a matrix that is the inverse of 'x'
29
+ # # Return a matrix that is the inverse of 'x'
30
+ inver_m <- x $ getInvMat()
31
+ if (! is.null(inver_m )){
32
+ message(" getting cached data" )
33
+ return (inver_m )
34
+ }
35
+ matrix <- x $ get()
36
+ inver_m <- solve(matrix , ... )
37
+ x $ setInvMat(inver_m )
38
+ inver_m
39
+
15
40
}
You can’t perform that action at this time.
0 commit comments