File tree 1 file changed +23
-6
lines changed 1 file changed +23
-6
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
+ # # Caching the inverse matrix computation result
3
2
4
- # # Write a short comment describing this function
3
+ # # wraps matrix with an object for caching the result
5
4
6
5
makeCacheMatrix <- function (x = matrix ()) {
7
-
6
+ m <- NULL
7
+ set <- function (y ) {
8
+ x <<- y
9
+ m <<- NULL
10
+ }
11
+ get <- function () x
12
+ setinverse <- function (inverse ) m <<- inverse
13
+ getinverse <- function () m
14
+ list (set = set , get = get ,
15
+ setinverse = setinverse ,
16
+ getinverse = getinverse )
8
17
}
9
18
10
19
11
- # # Write a short comment describing this function
20
+ # # gets inverse matrix for wrapped matrix
12
21
13
22
cacheSolve <- function (x , ... ) {
14
- # # Return a matrix that is the inverse of 'x'
23
+ m <- x $ getinverse()
24
+ if (! is.null(m )) {
25
+ message(" getting cached data" )
26
+ return (m )
27
+ }
28
+ data <- x $ get()
29
+ m <- solve(data , ... )
30
+ x $ setinverse(m )
31
+ m
15
32
}
You can’t perform that action at this time.
0 commit comments