File tree Expand file tree Collapse file tree 1 file changed +25
-9
lines changed Expand file tree Collapse file tree 1 file changed +25
-9
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
3
-
4
- # # Write a short comment describing this function
5
-
1
+ # # Takes a square matrix as argument and returns a list with functions
2
+ # # to solve the inverse and cache it to return it if was already called once;
6
3
makeCacheMatrix <- function (x = matrix ()) {
7
-
4
+ m <- NULL
5
+ set <- function (y ) {
6
+ x <<- y
7
+ m <<- NULL
8
+ }
9
+ get <- function () x
10
+ setinverse <- function (inverse ) m <<- inverse
11
+ getinverse <- function () m
12
+ list (set = set , get = get ,
13
+ setinverse = setinverse ,
14
+ getinverse = getinverse )
8
15
}
9
16
10
17
11
- # # Write a short comment describing this function
12
-
18
+ # # Takes a CacheMatrix list as argument and invokes the implemented
19
+ # # getInverse, which returns the inverted matrix, cached if it was already solved
20
+ # # called once or solves it and caches it for the next call;
13
21
cacheSolve <- function (x , ... ) {
14
- # # Return a matrix that is the inverse of 'x'
22
+ m <- x $ getinverse()
23
+ if (! is.null(m )) {
24
+ message(" getting cached data" )
25
+ return (m )
26
+ }
27
+ data <- x $ get()
28
+ m <- solve(data )
29
+ x $ setinverse(m )
30
+ m
15
31
}
You can’t perform that action at this time.
0 commit comments