File tree Expand file tree Collapse file tree 1 file changed +27
-5
lines changed Expand file tree Collapse file tree 1 file changed +27
-5
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
+ # # These functions enable the caching of the invert of a matrix by using getters and setters by function
2
+ # # on a matrix capsule (caching the computed invert matrix)
3
3
4
- # # Write a short comment describing this function
4
+ # # This function create a cacheable matrix with the default empty matrix
5
+ # # and return a list of function to modify the matrix or the cached invert of the matrix
5
6
6
7
makeCacheMatrix <- function (x = matrix ()) {
7
-
8
+ m <- NULL
9
+ set <- function (y ) {
10
+ x <<- y
11
+ m <<- NULL
12
+ }
13
+ get <- function () x
14
+ setinv <- function (inv ) m <<- inv
15
+ getinv <- function () m
16
+ list (set = set , get = get ,
17
+ setinv = setinv ,
18
+ getinv = getinv )
8
19
}
9
20
10
21
11
- # # Write a short comment describing this function
22
+ # # This function solves the invert of the 'x' cacheable matrix. 'x' must have been created
23
+ # # with makeCacheMatrix() and set using x$set and returns a matrix that is the inverse of 'x'
24
+ # # the '...' allow to pass others arguments to the solve method
12
25
13
26
cacheSolve <- function (x , ... ) {
14
27
# # Return a matrix that is the inverse of 'x'
28
+ m <- x $ getinv()
29
+ if (! is.null(m )) {
30
+ message(" getting cached data" )
31
+ return (m )
32
+ }
33
+ data <- x $ get()
34
+ m <- solve(data , ... )
35
+ x $ setinv(m )
36
+ m
15
37
}
You can’t perform that action at this time.
0 commit comments